2023-09-13 12:23:27 +02:00
|
|
|
package eu.dnetlib.validatorapi.exceptions;
|
|
|
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import org.springframework.web.context.request.WebRequest;
|
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
|
|
|
|
|
|
|
@ControllerAdvice
|
|
|
|
public class ExceptionHandler extends ResponseEntityExceptionHandler {
|
|
|
|
|
|
|
|
@ResponseBody
|
|
|
|
@org.springframework.web.bind.annotation.ExceptionHandler(value = {ValidationException.class})
|
|
|
|
protected ResponseEntity<ErrorMessage> handleValidationError(RuntimeException exception, WebRequest request) {
|
|
|
|
return new ResponseEntity(new ErrorMessage(exception.getMessage()), HttpStatus.BAD_REQUEST);
|
|
|
|
}
|
2023-09-13 12:22:21 +02:00
|
|
|
}
|