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(exceptions): add generic exception handler for UserException #737

Merged
merged 2 commits into from
Aug 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import com.netflix.spinnaker.kork.exceptions.HasAdditionalAttributes;
import com.netflix.spinnaker.kork.exceptions.UserException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
Expand Down Expand Up @@ -48,8 +49,6 @@ public class GenericExceptionHandlers extends ResponseEntityExceptionHandler {
@ExceptionHandler(AccessDeniedException.class)
public void handleAccessDeniedException(
Exception e, HttpServletResponse response, HttpServletRequest request) throws IOException {
logger.error("Access Denied", e);

storeException(request, response, e);

// avoid leaking any information that may be in `e.getMessage()` by returning a static error
Expand All @@ -64,7 +63,7 @@ public void handleNotFoundException(
response.sendError(HttpStatus.NOT_FOUND.value(), e.getMessage());
}

@ExceptionHandler(InvalidRequestException.class)
@ExceptionHandler({InvalidRequestException.class, UserException.class})
public void handleInvalidRequestException(
Exception e, HttpServletResponse response, HttpServletRequest request) throws IOException {
storeException(request, response, e);
Expand Down Expand Up @@ -134,6 +133,7 @@ private void storeException(
HttpServletRequest request, HttpServletResponse response, Exception ex) {
// store exception as an attribute of HttpServletRequest such that it can be referenced by
// GenericErrorController
logger.warn("Handled error in generic exception handler", ex);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added this because otherwise there often no logs of the exception that caused this handler to fire...

defaultErrorAttributes.resolveException(request, response, null, ex);
}

Expand Down