@Bean public RepositoryRestExceptionHandler repositoryRestExceptionHandler() { return new RepositoryRestExceptionHandler(applicationContext); }
/** * Handles {@link HttpMessageNotReadableException} by returning {@code 400 Bad Request}. * * @param o_O the exception to handle. * @return */ @ExceptionHandler ResponseEntity<ExceptionMessage> handleNotReadable(HttpMessageNotReadableException o_O) { return badRequest(new HttpHeaders(), o_O); }
private static ResponseEntity<ExceptionMessage> badRequest(HttpHeaders headers, Exception throwable) { return errorResponse(HttpStatus.BAD_REQUEST, headers, throwable); }
private static ResponseEntity<?> notFound(HttpHeaders headers) { return response(HttpStatus.NOT_FOUND, headers, null); }
/** * Handles {@link ResourceNotFoundException} by returning {@code 404 Not Found}. * * @param o_O the exception to handle. * @return */ @ExceptionHandler ResponseEntity<?> handleNotFound(ResourceNotFoundException o_O) { return notFound(new HttpHeaders()); }
private static <T> ResponseEntity<T> response(HttpStatus status, HttpHeaders headers) { return response(status, headers, null); }
/** * Handles {@link ResourceNotFoundException} by returning {@code 404 Not Found}. * * @param o_O the exception to handle. * @return */ @ExceptionHandler ResponseEntity<?> handleNotFound(ResourceNotFoundException o_O) { return notFound(new HttpHeaders()); }
private static ResponseEntity<ExceptionMessage> errorResponse(HttpStatus status, HttpHeaders headers, Exception exception) { if (exception != null) { String message = exception.getMessage(); LOG.error(message, exception); if (StringUtils.hasText(message)) { return response(status, headers, new ExceptionMessage(exception)); } } return response(status, headers, null); }
/** * Send a {@code 409 Conflict} in case of concurrent modification. * * @param o_O the exception to handle. * @return */ @ExceptionHandler({ OptimisticLockingFailureException.class, DataIntegrityViolationException.class }) ResponseEntity<ExceptionMessage> handleConflict(Exception o_O) { return errorResponse(HttpStatus.CONFLICT, new HttpHeaders(), o_O); }
@Bean public RepositoryRestExceptionHandler repositoryRestExceptionHandler() { return new RepositoryRestExceptionHandler(applicationContext); }
/** * Handles {@link HttpMessageNotReadableException} by returning {@code 400 Bad Request}. * * @param o_O the exception to handle. * @return */ @ExceptionHandler ResponseEntity<ExceptionMessage> handleNotReadable(HttpMessageNotReadableException o_O) { return badRequest(new HttpHeaders(), o_O); }
/** * Handles {@link RepositoryConstraintViolationException}s by returning {@code 400 Bad Request}. * * @param o_O the exception to handle. * @return */ @ExceptionHandler ResponseEntity<RepositoryConstraintViolationExceptionMessage> handleRepositoryConstraintViolationException( RepositoryConstraintViolationException o_O) { return response(HttpStatus.BAD_REQUEST, new HttpHeaders(), new RepositoryConstraintViolationExceptionMessage(o_O, messageSourceAccessor)); }
/** * Handle failures commonly thrown from code tries to read incoming data and convert or cast it to the right type by * returning {@code 500 Internal Server Error} and the thrown exception marshalled into JSON. * * @param o_O the exception to handle. * @return */ @ExceptionHandler({ InvocationTargetException.class, IllegalArgumentException.class, ClassCastException.class, ConversionFailedException.class, NullPointerException.class }) ResponseEntity<ExceptionMessage> handleMiscFailures(Exception o_O) { return errorResponse(HttpStatus.INTERNAL_SERVER_ERROR, new HttpHeaders(), o_O); }
/** * Send {@code 405 Method Not Allowed} and include the supported {@link org.springframework.http.HttpMethod}s in the * {@code Allow} header. * * @param o_O the exception to handle. * @return */ @ExceptionHandler ResponseEntity<Void> handle(HttpRequestMethodNotSupportedException o_O) { HttpHeaders headers = new HttpHeaders(); headers.setAllow(o_O.getSupportedHttpMethods()); return response(HttpStatus.METHOD_NOT_ALLOWED, headers); }
private static ResponseEntity<ExceptionMessage> badRequest(HttpHeaders headers, Exception throwable) { return errorResponse(HttpStatus.BAD_REQUEST, headers, throwable); }
/** * Handles {@link ETagDoesntMatchException} by returning {@code 412 Precondition Failed}. * * @param o_O the exception to handle. * @return */ @ExceptionHandler ResponseEntity<Void> handle(ETagDoesntMatchException o_O) { HttpHeaders headers = o_O.getExpectedETag().addTo(new HttpHeaders()); return response(HttpStatus.PRECONDITION_FAILED, headers); }
/** * Send a {@code 409 Conflict} in case of concurrent modification. * * @param o_O the exception to handle. * @return */ @ExceptionHandler({ OptimisticLockingFailureException.class, DataIntegrityViolationException.class }) ResponseEntity<ExceptionMessage> handleConflict(Exception o_O) { return errorResponse(HttpStatus.CONFLICT, new HttpHeaders(), o_O); }
private static ResponseEntity<?> notFound(HttpHeaders headers) { return response(HttpStatus.NOT_FOUND, headers, null); }
/** * Handle failures commonly thrown from code tries to read incoming data and convert or cast it to the right type by * returning {@code 500 Internal Server Error} and the thrown exception marshalled into JSON. * * @param o_O the exception to handle. * @return */ @ExceptionHandler({ InvocationTargetException.class, IllegalArgumentException.class, ClassCastException.class, ConversionFailedException.class, NullPointerException.class }) ResponseEntity<ExceptionMessage> handleMiscFailures(Exception o_O) { return errorResponse(HttpStatus.INTERNAL_SERVER_ERROR, new HttpHeaders(), o_O); }
private static <T> ResponseEntity<T> response(HttpStatus status, HttpHeaders headers) { return response(status, headers, null); }