Skip to content

Commit

Permalink
feat: Exception을 throw 하지 않고 request.setAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
LJH098 committed Jan 2, 2025
1 parent eb4693d commit 9051323
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ public void commence(
HttpServletResponse response,
AuthenticationException authException)
throws IOException {
Object exceptionAttribute = request.getAttribute("javax.servlet.error.exception");
if (exceptionAttribute == null) {

if (request.getAttribute("swaggerCannotProdException") != null) {
resolver.resolveException(
request,
response,
null,
(Exception) request.getAttribute("swaggerCannotProdException"));
} else if (request.getAttribute("exception") == null) {
handleAuthenticationException(response);
} else if (exceptionAttribute instanceof Exception exception) {
resolver.resolveException(request, response, null, exception);
} else {
handleAuthenticationException(response);
resolver.resolveException(
request, response, null, (Exception) request.getAttribute("exception"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ protected void doFilterInternal(
// prod 환경에서 swagger 요청을 차단
if (Boolean.TRUE.equals(springEnvironmentHelper.isProdProfile())
&& isSwaggerRequest(request)) {
request.setAttribute(
"swaggerCannotProdException", SwaggerCannotProdException.EXCEPTION);
throw SwaggerCannotProdException.EXCEPTION;
}

Expand Down

0 comments on commit 9051323

Please sign in to comment.