Untitled
jeclipse
plain_text
2 years ago
647 B
8
Indexable
@ExceptionHandler(APIException.class)
public ResponseEntity<ErrorDTO> handleException(APIException exception) {
HttpStatus httpStatus = HttpStatus.resolve(exception.getStatusCode());
// Default to INTERNAL_SERVER_ERROR if the status code is not recognized
if (httpStatus == null) {
httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
}
log.error(exception.getResponseBody());
return ResponseEntity.status(httpStatus)
.body(
ErrorDTO.builder()
.code(httpStatus.getReasonPhrase())
.message(exception.getResponseBody())
.build());
}Editor is loading...
Leave a Comment