/
allalex
/
Spring-AOP
Обзор
Документация
Войти
/
allalex
/
Spring-AOP
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/com/springaopopenschool1/firsttask/exception/ExceptionHandlerGlobal.java
24 строки
965 B
Alexey Layko
рефактор + выделение тестовых настроек для режима test
09 май 2024, 00:52
09 май 2024, 00:52
fb0cffd
Код
Авторство
О чём код?
package com.springaopopenschool1.firsttask.exception; import com.springaopopenschool1.firsttask.model.AppError; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; @ControllerAdvice @Slf4j public class ExceptionHandlerGlobal { @ExceptionHandler(value = ResourceNotFoundException.class) public ResponseEntity<AppError> catchResourceNotFoundException(ResourceNotFoundException e) { log.error(e.getMessage(), e); return new ResponseEntity<>(new AppError(HttpStatus.NOT_FOUND.value(), e.getMessage()), HttpStatus.NOT_FOUND); } @ExceptionHandler(value = Exception.class) public ResponseEntity<Object> handleException(Exception e) { return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } }