-
Notifications
You must be signed in to change notification settings - Fork 740
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
Conversation
2858642
to
3e00378
Compare
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 |
|
||
@ExceptionHandler(Exception.class) | ||
void handleException(Exception e, HttpServletResponse response, HttpServletRequest request) throws IOException { | ||
logger.error("Internal Server Error", e); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
I like it! |
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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 } ```
3e00378
to
8135d5a
Compare
The errant I'll refactor out to |
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 } ```
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: