From 6d1b89609b3f9ef2f90f574305880b9d160de11d Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Thu, 21 Aug 2025 16:29:27 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0]=20GlobalExceptionHandler=EC=97=90=20?= =?UTF-8?q?=EC=9D=BC=EB=B0=98=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=20=EA=B8=B0=EB=8A=A5=20=ED=86=B5=ED=95=A9.?= =?UTF-8?q?=20CustomAuthenticationFailureHandler=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20=EC=A4=84=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0.=20JwtTokenValidationFilter=EC=97=90=EC=84=9C=20JWT?= =?UTF-8?q?=20=EA=B2=80=EC=A6=9D=20=EC=98=A4=EB=A5=98=20=EC=8B=9C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=20=EA=B8=B0=EB=A1=9D=20=EC=B6=94=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/CustomAuthenticationFailureHandler.java | 1 - .../global/exception/GlobalExceptionHandler.java | 10 ++++++++++ .../global/security/JwtTokenValidationFilter.java | 5 +---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/bio/bio_backend/global/exception/CustomAuthenticationFailureHandler.java b/src/main/java/com/bio/bio_backend/global/exception/CustomAuthenticationFailureHandler.java index 7cc2539..d5b59d0 100644 --- a/src/main/java/com/bio/bio_backend/global/exception/CustomAuthenticationFailureHandler.java +++ b/src/main/java/com/bio/bio_backend/global/exception/CustomAuthenticationFailureHandler.java @@ -45,6 +45,5 @@ public class CustomAuthenticationFailureHandler implements AuthenticationFailure String jsonResponse = objectMapper.writeValueAsString(apiResponse); response.getWriter().write(jsonResponse); - } } diff --git a/src/main/java/com/bio/bio_backend/global/exception/GlobalExceptionHandler.java b/src/main/java/com/bio/bio_backend/global/exception/GlobalExceptionHandler.java index 5abcddc..e1ccf03 100644 --- a/src/main/java/com/bio/bio_backend/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/bio/bio_backend/global/exception/GlobalExceptionHandler.java @@ -8,8 +8,10 @@ import com.bio.bio_backend.global.dto.ApiResponseDto; import com.bio.bio_backend.global.constants.ApiResponseCode; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import lombok.extern.slf4j.Slf4j; @RestControllerAdvice +@Slf4j public class GlobalExceptionHandler { @ExceptionHandler(ApiException.class) @@ -29,6 +31,14 @@ public class GlobalExceptionHandler { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); } + @ExceptionHandler(Exception.class) + public ResponseEntity> handleException(Exception e) { + log.error("Unexpected error occurred", e); + + ApiResponseDto response = ApiResponseDto.fail(ApiResponseCode.COMMON_INTERNAL_SERVER_ERROR); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + // 검증 오류 상세 정보를 위한 내부 클래스 private record ValidationError(String field, String message) { } } diff --git a/src/main/java/com/bio/bio_backend/global/security/JwtTokenValidationFilter.java b/src/main/java/com/bio/bio_backend/global/security/JwtTokenValidationFilter.java index 9464e1f..7fabe85 100644 --- a/src/main/java/com/bio/bio_backend/global/security/JwtTokenValidationFilter.java +++ b/src/main/java/com/bio/bio_backend/global/security/JwtTokenValidationFilter.java @@ -87,15 +87,12 @@ public class JwtTokenValidationFilter extends OncePerRequestFilter { } filterChain.doFilter(request, response); - return; } else { sendJsonResponse(response, ApiResponseDto.fail(ApiResponseCode.ALL_TOKEN_INVALID)); - return; } } catch (Exception e) { - request.setAttribute("exception", e); + log.error("JWT 토큰 검증 중 오류 발생", e); sendJsonResponse(response, ApiResponseDto.fail(ApiResponseCode.COMMON_INTERNAL_SERVER_ERROR)); - return; } }