|
5 | 5 | import static com.example.solidconnection.common.exception.ErrorCode.JSON_PARSING_FAILED; |
6 | 6 | import static com.example.solidconnection.common.exception.ErrorCode.JWT_EXCEPTION; |
7 | 7 | import static com.example.solidconnection.common.exception.ErrorCode.NOT_DEFINED_ERROR; |
| 8 | +import static com.example.solidconnection.common.exception.ErrorCode.REFRESH_TOKEN_EXPIRED; |
8 | 9 |
|
| 10 | +import com.example.solidconnection.auth.controller.RefreshTokenCookieManager; |
| 11 | +import com.example.solidconnection.auth.exception.AuthException; |
9 | 12 | import com.example.solidconnection.common.response.ErrorResponse; |
10 | 13 | import com.fasterxml.jackson.databind.exc.InvalidFormatException; |
11 | 14 | import io.jsonwebtoken.JwtException; |
| 15 | +import jakarta.servlet.http.HttpServletResponse; |
12 | 16 | import java.util.ArrayList; |
13 | 17 | import java.util.List; |
| 18 | +import lombok.RequiredArgsConstructor; |
14 | 19 | import lombok.extern.slf4j.Slf4j; |
15 | 20 | import org.springframework.dao.DataIntegrityViolationException; |
16 | 21 | import org.springframework.http.HttpStatus; |
|
21 | 26 |
|
22 | 27 | @Slf4j |
23 | 28 | @ControllerAdvice |
| 29 | +@RequiredArgsConstructor |
24 | 30 | public class CustomExceptionHandler { |
25 | 31 |
|
| 32 | + private final RefreshTokenCookieManager refreshTokenCookieManager; |
| 33 | + |
| 34 | + @ExceptionHandler(AuthException.class) |
| 35 | + protected ResponseEntity<ErrorResponse> handleAuthException( |
| 36 | + AuthException ex, |
| 37 | + HttpServletResponse response |
| 38 | + ) { |
| 39 | + log.error("인증 예외 발생 : {}", ex.getMessage()); |
| 40 | + if (ex.getErrorCode().equals(REFRESH_TOKEN_EXPIRED)) { |
| 41 | + refreshTokenCookieManager.deleteCookie(response); |
| 42 | + } |
| 43 | + ErrorResponse errorResponse = new ErrorResponse(ex); |
| 44 | + return ResponseEntity |
| 45 | + .status(ex.getCode()) |
| 46 | + .body(errorResponse); |
| 47 | + } |
| 48 | + |
26 | 49 | @ExceptionHandler(CustomException.class) |
27 | 50 | protected ResponseEntity<ErrorResponse> handleCustomException(CustomException ex) { |
28 | 51 | log.error("커스텀 예외 발생 : {}", ex.getMessage()); |
|
0 commit comments