Untitled

 avatar
jeclipse
plain_text
11 days ago
647 B
1
Indexable
Never
 @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());
  }
Leave a Comment