Java Code Examples for org.springframework.http.HttpStatus#toString()

The following examples show how to use org.springframework.http.HttpStatus#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResponseExceptionHandler.java    From spring-batch-rest with Apache License 2.0 6 votes vote down vote up
@ExceptionHandler(BatchRuntimeException.class)
protected ResponseEntity<Object> handleBatchRuntimeException(BatchRuntimeException e, WebRequest request) {
    log.error("Request {} failed with {}", request, e);
    Throwable cause = e.getCause();
    HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
    if (cause instanceof DuplicateJobException
            || cause instanceof JobExecutionAlreadyRunningException
            || cause instanceof JobInstanceAlreadyCompleteException)
        status = HttpStatus.CONFLICT;
    else if (cause instanceof JobParametersInvalidException
        || cause instanceof JobParametersNotFoundException)
        status = HttpStatus.BAD_REQUEST;
    else if (cause instanceof NoSuchJobException
        || cause instanceof NoSuchJobExecutionException
        || cause instanceof NoSuchJobInstanceException)
        status = HttpStatus.NOT_FOUND;

    ApiError apiError = new ApiError(status.toString(), cause.getMessage(), cause.getClass().getSimpleName(), e.getMessage());
    return handleExceptionInternal(e, apiError, new HttpHeaders(), status, request);
}
 
Example 2
Source File: ResponseExceptionHandler.java    From spring-batch-rest with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(Exception.class)
protected ResponseEntity<Object> handleAnyException(Exception e, WebRequest request) {
    log.error("Request {} failed with {}", request, e);
    String message = e.getMessage();
    String causeMessage = "";
    if (e.getCause() != null)
        causeMessage = e.getCause().getMessage();
    HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
    ApiError apiError = new ApiError(status.toString(), message, e.getClass().getSimpleName(), causeMessage);
    return handleExceptionInternal(e, apiError, new HttpHeaders(), status, request);
}