Web services RESTful com Spring framework e JPA
Aproveitando o curso "Web services RESTful com Spring framework e JPA", inclui na classe RestExceptionHandler o status UNAUTHORIZED . Como trato o erro?
@ExceptionHandler({NaoAutorizadoServiceException.class})
public ResponseEntity<Object> naoAutorizado(NaoAutorizadoServiceException ex,
WebRequest request) {
return handleExceptionInternal(
ex, DetalheErro.builder()
.addErro(ex.getMessage())
.addStatus(UNAUTHORIZED)
.addHttpMethod(getHttpMethod(request))
.addPath(getPath(request))
.build(),
new HttpHeaders(), UNAUTHORIZED, request);
}
@ExceptionHandler({NaoAutorizadoServiceException.class})
public ResponseEntity<Object> naoAutorizado(NaoAutorizadoServiceException ex,
WebRequest request) {
return handleExceptionInternal(
ex, DetalheErro.builder()
.addErro(ex.getMessage())
.addStatus(UNAUTHORIZED)
.addHttpMethod(getHttpMethod(request))
.addPath(getPath(request))
.build(),
new HttpHeaders(), UNAUTHORIZED, request);
}
Anderson Rodrigues
Curtidas 0