Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): Generic exception handling #423

Merged
merged 1 commit into from
Jul 11, 2017

Conversation

ajordens
Copy link
Contributor

Introduces a single NotFoundException that can be used in place of all
previous *NotFoundException classes (ie. ApplicationNotFoundException,
SecurityGroupNotFoundException, etc).

The default ErrorController has been replaced with one that will always
return application/json.

A stacktrace will be included if ?trace=true is appended to the request.

Example error response:

{
  "error": "Not Found",
  "exception": "com.netflix.spinnaker.gate.exceptions.NotFoundException",
  "message": "Application not found (id: some_application_name)",
  "status": 404,
  "timestamp": 1499731805410
}

@ajordens ajordens force-pushed the better-exception-handling branch from 2858642 to 3e00378 Compare July 11, 2017 00:54
@ajordens ajordens requested review from robzienert and cfieber July 11, 2017 00:55
@ajordens
Copy link
Contributor Author

An attempt at cleaning up how exceptions are propagated out of a service.

If this approach seems reasonable, I would pull a few bits up to kork-web for re-use across all services.


@ExceptionHandler(Exception.class)
void handleException(Exception e, HttpServletResponse response, HttpServletRequest request) throws IOException {
logger.error("Internal Server Error", e);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensures we get a log message for otherwise unhandled exceptions (by default an exception w/ a Handler does not log).

throw new ProjectNotFoundException("Project not found (projectId: ${projectId})")
}
result
return projectService.get(projectId)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous bits were bogus anyways ... you'll never get a null value back (rather a RetrofitError).


@Override
public Map<String, Object> getAdditionalAttributes() {
return Collections.singletonMap("my-attribute", "my-value");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended to stick around?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch ... this was a crazy test.

@robzienert
Copy link
Member

I like it!

Copy link
Contributor

@cfieber cfieber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from what looks like extraneous additionalAttributes on NotFoundException


@Override
public Map<String, Object> getAdditionalAttributes() {
return Collections.singletonMap("my-attribute", "my-value");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the correct additionalAttributes?

Introduces a single NotFoundException that can be used in place of all
previous *NotFoundException classes (ie. ApplicationNotFoundException,
SecurityGroupNotFoundException, etc).

The default ErrorController has been replaced with one that will always
return application/json.

A stacktrace will be included if ?trace=true is appended to the request.

Example error response:

```
{
  "error": "Not Found",
  "exception": "com.netflix.spinnaker.gate.exceptions.NotFoundException",
  "message": "Application not found (id: some_application_name)",
  "status": 404,
  "timestamp": 1499731805410
}
```
@ajordens ajordens force-pushed the better-exception-handling branch from 3e00378 to 8135d5a Compare July 11, 2017 01:17
@ajordens
Copy link
Contributor Author

The errant additionalAttributes has been removed ... will merge after metal travis gives the 👍 .

I'll refactor out to kork-web once this survives a few hours in production.

@ajordens ajordens merged commit d58f39c into spinnaker:master Jul 11, 2017
@ajordens ajordens deleted the better-exception-handling branch July 11, 2017 01:25
ajordens added a commit to ajordens/kork that referenced this pull request Jul 11, 2017
ajordens added a commit to ajordens/kork that referenced this pull request Jul 11, 2017
ajordens added a commit to spinnaker/kork that referenced this pull request Jul 11, 2017
danielpeach pushed a commit to danielpeach/gate that referenced this pull request May 24, 2018
Introduces a single NotFoundException that can be used in place of all
previous *NotFoundException classes (ie. ApplicationNotFoundException,
SecurityGroupNotFoundException, etc).

The default ErrorController has been replaced with one that will always
return application/json.

A stacktrace will be included if ?trace=true is appended to the request.

Example error response:

```
{
  "error": "Not Found",
  "exception": "com.netflix.spinnaker.gate.exceptions.NotFoundException",
  "message": "Application not found (id: some_application_name)",
  "status": 404,
  "timestamp": 1499731805410
}
```
@spinnakerbot spinnakerbot mentioned this pull request May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants