feat(exception): añadido handler para PythonApiException y control para IllegalArgumentException

parent 5f7d301c
......@@ -12,9 +12,9 @@ import java.time.LocalDateTime;
@RestControllerAdvice
public class ExceptionController {
@ExceptionHandler(UnprocessableEntityException.class)
@ExceptionHandler({UnprocessableEntityException.class, IllegalArgumentException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity<ErrorMessage> handle(UnprocessableEntityException ex) {
public ResponseEntity<ErrorMessage> handle(RuntimeException ex) {
return new ResponseEntity<>(new ErrorMessage(LocalDateTime.now(), HttpStatus.BAD_REQUEST.value(),
ex.getMessage()), HttpStatusCode.valueOf(HttpStatus.BAD_REQUEST.value()));
}
......@@ -26,4 +26,15 @@ public class ExceptionController {
ex.getMessage()), HttpStatusCode.valueOf(HttpStatus.NOT_FOUND.value()));
}
@ExceptionHandler(PythonApiException.class)
public ResponseEntity<ErrorMessage> handle(PythonApiException ex) {
return ResponseEntity
.status(ex.getStatus()).
body(new ErrorMessage(
LocalDateTime.now(),
ex.getStatus().value(),
ex.getMessage()
));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment