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; } }