fix: 유효하지 않은 토큰으로 api 요청 시 500 error 발생 버그 수정 #210
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
관련 이슈
작업 내용
문제 내용
유효하지 않은 토큰으로 API 요청 시 JwtAuthenticationFilter에서 발생한 예외(CustomException 등)가 ExceptionHandlerFilter에서 잡히지 않고, WAS 기본 예외 처리로 넘어가면서 500 에러가 발생하는 문제가 있었습니다.
문제 원인
문제 해결
필터 순서를 원복하고, Spring Security의 기본 제공 기능인 AccessDeniedHandler와 AuthenticationEntryPoint를 활용해 인증/인가 예외를 처리하도록 변경했습니다.
CustomAuthenticationEntryPoint, CustomAccessDeniedHandler를 구현하여 예외 발생 시 일관된 JSON 응답이 내려가도록 했습니다.
리뷰 요구사항 (선택)
일단 필터 순서변경만으로 인가 관련 예외 잡는 것과 jwtAuthenticationFilter 예외를 잡는 것을 동시에 해결하는 것이 어려울 거 같아 이 방식으로 구현을 했는데 추후 더 나은 해결책을 찾으면 그거로 적용해보도록 하겠습니다 🥲