|
2 | 2 |
|
3 | 3 | import org.slf4j.Logger; |
4 | 4 | import org.slf4j.LoggerFactory; |
| 5 | +import org.springframework.context.support.MessageSourceAccessor; |
5 | 6 | import org.springframework.http.HttpStatus; |
6 | 7 | import org.springframework.web.bind.annotation.ControllerAdvice; |
7 | 8 | import org.springframework.web.bind.annotation.ExceptionHandler; |
|
17 | 18 | public class GlobalExceptionHandler { |
18 | 19 | private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); |
19 | 20 |
|
| 21 | + private final MessageSourceAccessor messageSourceAccessor; |
| 22 | + |
| 23 | + public GlobalExceptionHandler(MessageSourceAccessor messageSourceAccessor) { |
| 24 | + this.messageSourceAccessor = messageSourceAccessor; |
| 25 | + } |
| 26 | + |
20 | 27 | @ExceptionHandler(Exception.class) |
21 | 28 | public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception { |
22 | 29 | log.error("Exception at request " + req.getRequestURL(), e); |
23 | 30 | Throwable rootCause = ValidationUtil.logAndGetRootCause(log, req, e, true, ErrorType.APP_ERROR); |
24 | 31 |
|
25 | 32 | HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; |
26 | 33 | ModelAndView mav = new ModelAndView("exception", |
27 | | - Map.of("exception", rootCause, "message", ValidationUtil.getMessage(rootCause), "status", httpStatus)); |
| 34 | + Map.of("exception", rootCause, "message", ValidationUtil.getMessage(rootCause), |
| 35 | + "typeMessage", messageSourceAccessor.getMessage(ErrorType.APP_ERROR.getErrorCode()), |
| 36 | + "status", httpStatus)); |
28 | 37 | mav.setStatus(httpStatus); |
29 | 38 |
|
30 | 39 | // Interceptor is not invoked, put userTo |
|
0 commit comments