Tratamento de Exceções
Vá no pacote Controller, e crie um subpacote "exceptions".
Crie:
StandardError
ResourceExceptionHandler
Atualizado
Vá no pacote Controller, e crie um subpacote "exceptions".
Crie:
StandardError
public class StandardError implements Serializable {
private static final long serialVersionUID = 1L;
private Long timestamp;
private Integer status;
private String error;
private String message;
private String path;
}
ResourceExceptionHandler
@ControllerAdvice
public class ResourceExceptionHandler {
@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<StandardError> resourceNotFound(ResourceNotFoundException e, HttpServletRequest request) {
HttpStatus status = HttpStatus.NOT_FOUND;
StandardError error = new StandardError();
error.setError("Not found");
error.setMessage(e.getMessage());
error.setPath(request.getRequestURI());
error.setStatus(status.value());
error.setTimestamp(Instant.now());
return ResponseEntity.status(status).body(error);
}
}
Atualizado