File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Spring_part_25/src/main/java/spring/oldboy/http/handler Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ package spring .oldboy .http .handler ;
2+
3+ import jakarta .servlet .http .HttpServletRequest ;
4+ import lombok .extern .slf4j .Slf4j ;
5+ import org .springframework .web .bind .annotation .ControllerAdvice ;
6+ import org .springframework .web .bind .annotation .ExceptionHandler ;
7+
8+ /* Подключаем логгер */
9+ @ Slf4j
10+ /*
11+ Дабы сделать наш обработчик исключений при валидации глобальным
12+ помечаем его как @ControllerAdvice, данная аннотация если посмотреть
13+ ее код помечена как @Component, т.е. она является bean-ом.
14+
15+ Lesson 97: Указываем ошибки какого пакета контроллеров обрабатывает
16+ это хандлер, в данном случае обычных не REST.
17+ */
18+ @ ControllerAdvice (basePackages = "spring.oldboy.http.controller" )
19+ /* Применив extends ResponseEntityExceptionHandler получим широкий диапазон отлова исключений */
20+ public class ControllerExceptionHandler {
21+
22+ @ ExceptionHandler (Exception .class )
23+ public String handleExceptions (Exception exception , HttpServletRequest request ) {
24+ log .error ("Failed to return response" , exception );
25+ return "error/error500" ;
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments