|
1 | 1 | package com.moing.backend.global.exception;
|
2 | 2 |
|
| 3 | +import com.moing.backend.global.config.slack.exception.dto.ExceptionEvent; |
3 | 4 | import com.moing.backend.global.response.ErrorCode;
|
4 | 5 | import com.moing.backend.global.response.ErrorResponse;
|
5 |
| -import com.moing.backend.global.util.SlackService; |
6 | 6 | import lombok.RequiredArgsConstructor;
|
7 | 7 | import lombok.extern.slf4j.Slf4j;
|
| 8 | +import org.springframework.context.ApplicationEventPublisher; |
| 9 | +import org.springframework.context.support.DefaultMessageSourceResolvable; |
8 | 10 | import org.springframework.http.HttpStatus;
|
9 | 11 | import org.springframework.http.ResponseEntity;
|
10 | 12 | import org.springframework.http.converter.HttpMessageNotReadableException;
|
11 | 13 | import org.springframework.web.HttpRequestMethodNotSupportedException;
|
12 | 14 | import org.springframework.web.bind.MethodArgumentNotValidException;
|
13 | 15 | import org.springframework.web.bind.annotation.ExceptionHandler;
|
14 | 16 | import org.springframework.web.bind.annotation.RestControllerAdvice;
|
15 |
| -import org.springframework.context.support.DefaultMessageSourceResolvable; |
16 | 17 |
|
17 | 18 | import javax.servlet.http.HttpServletRequest;
|
18 | 19 | import java.util.function.Consumer;
|
|
25 | 26 | public class GlobalExceptionHandler {
|
26 | 27 |
|
27 | 28 | private static final String LOG_FORMAT = "Class : {}, Code : {}, Message : {}";
|
28 |
| - private final SlackService slackService; |
| 29 | + private final ApplicationEventPublisher eventPublisher; |
29 | 30 |
|
30 | 31 | @ExceptionHandler(ApplicationException.class)
|
31 | 32 | public ResponseEntity<ErrorResponse> handleApplicationException(ApplicationException ex) {
|
@@ -57,7 +58,7 @@ public ResponseEntity<ErrorResponse> httpRequestNotSupportedExceptionHandler(Htt
|
57 | 58 |
|
58 | 59 | @ExceptionHandler(Exception.class)
|
59 | 60 | public ResponseEntity<ErrorResponse> internalServerErrorHandler(Exception ex, HttpServletRequest request) {
|
60 |
| - slackService.sendSlackAlertErrorLog(ex, request); |
| 61 | + eventPublisher.publishEvent(new ExceptionEvent(request, ex)); |
61 | 62 | return handleException(ex, ErrorCode.INTERNAL_SERVER_ERROR, ErrorCode.INTERNAL_SERVER_ERROR.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR, log::error);
|
62 | 63 | }
|
63 | 64 |
|
|
0 commit comments