[예외 처리 개선] GlobalExceptionHandler에 일반 예외 처리 메서드 추가 및 로그 기능 통합. CustomAuthenticationFailureHandler에서 불필요한 줄 제거. JwtTokenValidationFilter에서 JWT 검증 오류 시 로그 기록 추가.

This commit is contained in:
2025-08-21 16:29:27 +09:00
parent baaa003d9a
commit 6d1b89609b
3 changed files with 11 additions and 5 deletions

View File

@@ -45,6 +45,5 @@ public class CustomAuthenticationFailureHandler implements AuthenticationFailure
String jsonResponse = objectMapper.writeValueAsString(apiResponse);
response.getWriter().write(jsonResponse);
}
}

View File

@@ -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<ApiResponseDto<Void>> handleException(Exception e) {
log.error("Unexpected error occurred", e);
ApiResponseDto<Void> response = ApiResponseDto.fail(ApiResponseCode.COMMON_INTERNAL_SERVER_ERROR);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
// 검증 오류 상세 정보를 위한 내부 클래스
private record ValidationError(String field, String message) { }
}

View File

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