|
5 | 5 | import com.juu.juulabel.common.response.CommonResponse; |
6 | 6 | import io.jsonwebtoken.ExpiredJwtException; |
7 | 7 | import io.jsonwebtoken.MalformedJwtException; |
| 8 | +import io.sentry.Sentry; |
8 | 9 | import lombok.extern.slf4j.Slf4j; |
9 | 10 | import org.springframework.http.ResponseEntity; |
10 | 11 | import org.springframework.web.bind.MethodArgumentNotValidException; |
|
17 | 18 | @RestControllerAdvice |
18 | 19 | public class GlobalExceptionHandler { |
19 | 20 |
|
| 21 | + @ExceptionHandler(Exception.class) |
| 22 | + public ResponseEntity<CommonResponse<String>> handle(Exception e) { |
| 23 | + log.error("Exception :", e); |
| 24 | + Sentry.captureException(e); |
| 25 | + return CommonResponse.fail(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); |
| 26 | + } |
| 27 | + |
20 | 28 | @ExceptionHandler(BaseException.class) |
21 | 29 | public ResponseEntity<CommonResponse<String>> handle(BaseException e) { |
22 | | - log.error("BaseException : {} ", e.getMessage()); |
| 30 | + log.error("BaseException :", e); |
| 31 | + Sentry.captureException(e); |
23 | 32 | return CommonResponse.fail(e.getErrorCode()); |
24 | 33 | } |
25 | 34 |
|
26 | 35 | @ExceptionHandler(RuntimeException.class) |
27 | 36 | public ResponseEntity<CommonResponse<String>> handle(RuntimeException e) { |
28 | | - log.error("RuntimeException : {}", e.getMessage()); |
| 37 | + log.error("RuntimeException :", e); |
| 38 | + Sentry.captureException(e); |
29 | 39 | return CommonResponse.fail(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage()); |
30 | 40 | } |
31 | 41 |
|
32 | 42 | @ExceptionHandler(MethodArgumentNotValidException.class) |
33 | 43 | public ResponseEntity<CommonResponse<String>> handle(MethodArgumentNotValidException e) { |
34 | | - log.error("MethodArgumentNotValidException : {}", e.getMessage()); |
| 44 | + log.error("MethodArgumentNotValidException :", e); |
35 | 45 | return CommonResponse.fail(ErrorCode.VALIDATION_ERROR, Objects.requireNonNull(e.getBindingResult().getFieldError()).getDefaultMessage()); |
36 | 46 | } |
37 | 47 |
|
38 | 48 | @ExceptionHandler(ExpiredJwtException.class) |
39 | 49 | public ResponseEntity<CommonResponse<String>> handle(ExpiredJwtException e) { |
40 | | - log.error("ExpiredJwtException : {}", e.getMessage()); |
| 50 | + log.error("ExpiredJwtException :", e); |
41 | 51 | return CommonResponse.fail(ErrorCode.EXPIRED_JWT_EXCEPTION, e.getMessage()); |
42 | 52 | } |
43 | 53 |
|
44 | 54 | @ExceptionHandler(MalformedJwtException.class) |
45 | 55 | public ResponseEntity<CommonResponse<String>> handle(MalformedJwtException e) { |
46 | | - log.error("MalformedJwtException : {}", e.getMessage()); |
| 56 | + log.error("MalformedJwtException :", e); |
47 | 57 | return CommonResponse.fail(ErrorCode.MALFORMED_JWT_EXCEPTION, "잘못된 토큰 형식입니다."); |
48 | 58 | } |
49 | 59 |
|
|
0 commit comments