Example usage for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR

List of usage examples for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR.

Prototype

HttpStatus INTERNAL_SERVER_ERROR

To view the source code for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR.

Click Source Link

Document

500 Internal Server Error .

Usage

From source file:io.curly.commons.config.feign.ErrorDecoderFactory.java

public static Exception create(HttpStatus httpStatus, String reason) {
    if (httpStatus.equals(HttpStatus.NOT_FOUND)) {
        return new ResourceNotFoundException(reason);
    } else if (httpStatus.equals(HttpStatus.BAD_REQUEST)) {
        return new BadRequestException(reason);
    } else if (httpStatus.equals(HttpStatus.INTERNAL_SERVER_ERROR)) {
        return new InternalServerErrorException(reason);
    } else if (httpStatus.equals(HttpStatus.UNAUTHORIZED)) {
        return new UnauthorizedException(reason);
    } else if (httpStatus.equals(HttpStatus.UNSUPPORTED_MEDIA_TYPE)) {
        return new UnsupportedMediaTypeException(reason);
    }//from   w  ww.jav  a  2s.co m
    return new BadRequestException(reason);

}

From source file:com.swcguild.blacksmithblogcapstone.validation.RestValidationHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody//from   w w w .  ja v  a  2s . c  om
public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) {

    BindingResult result = e.getBindingResult();
    List<FieldError> fieldErrors = result.getFieldErrors();

    ValidationErrorContainer errors = new ValidationErrorContainer();
    for (FieldError currentError : fieldErrors) {
        errors.addValidationError(currentError.getField(), currentError.getDefaultMessage());
    }

    return errors;

}

From source file:com.dhenton9000.birt.controllers.support.ExceptionControllerAdvice.java

@ExceptionHandler(Exception.class)
public ResponseEntity<GenericError> handleException(Exception e) {

    GenericError ge = new GenericError(e);
    return new ResponseEntity<GenericError>(ge, HttpStatus.INTERNAL_SERVER_ERROR);
}

From source file:com.hp.autonomy.frontend.find.core.view.AbstractViewController.java

@ExceptionHandler
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView handleGeneralException(final Exception e, final HttpServletRequest request,
        final HttpServletResponse response) {
    response.reset();//from ww w  .j  av a  2s. c  o  m

    final UUID uuid = UUID.randomUUID();
    log.error("Unhandled exception with uuid {}", uuid);
    log.error("Stack trace", e);

    final Locale locale = Locale.ENGLISH;

    return buildErrorModelAndView(request,
            messageSource.getMessage("error.internalServerErrorMain", null, locale),
            messageSource.getMessage("error.internalServerErrorSub", new Object[] { uuid }, locale));
}

From source file:com.javiermoreno.springboot.rest.RestExceptionHandler.java

@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody//  w w w . j a v a  2 s.com
public ExceptionReportDTO generalException(Exception exc) {
    ExceptionReportDTO report = new ExceptionReportDTO();
    report.originalErrorMessage = exc.getMessage();
    return report;
}

From source file:com.carlomicieli.jtrains.infrastructure.web.ResponsesTests.java

@Test
public void shouldCreateResponsesForErrors() {
    ResponseEntity<VndErrors> error = Responses.error(new RuntimeException("Error message"),
            HttpStatus.INTERNAL_SERVER_ERROR, "details");
    assertThat(error).isNotNull();/*from   w ww. ja v a  2s. c  om*/
    assertThat(error.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
    assertThat(error.getBody()).isEqualTo(new VndErrors("details", "Error message"));
}

From source file:com.sg.rest.controllers.RestErrorHandler.java

@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody//from  w ww.  ja v  a 2s  .  c  o m
public ServerException processException(Exception ex) throws Exception {

    ServerException dto = new ServerException();
    LOGGER.error("Rest exception occured " + dto.getEventRef().getId() + ": ", ex);

    if (AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class) != null) {
        throw ex;
    }

    return dto;
}

From source file:com.boundlessgeo.geoserver.api.exceptions.AppExceptionHandler.java

@ExceptionHandler(Exception.class)
public @ResponseBody JSONObj error(Exception e, HttpServletResponse response) {

    HttpStatus status = status(e);/*w w w .j a v  a  2s  .co  m*/
    response.setStatus(status.value());

    // log at warning if 500, else debug
    LOG.log(status == HttpStatus.INTERNAL_SERVER_ERROR ? Level.WARNING : Level.FINE, e.getMessage(), e);
    return IO.error(new JSONObj(), e);
}

From source file:com.aspose.showcase.qrcodegen.web.api.controller.RestResponseEntityExceptionHandler.java

@ExceptionHandler(value = { BarCodeException.class })
protected ResponseEntity<Object> handleConflict(RuntimeException ex, WebRequest request) {

    String bodyOfResponse = "Internal Server Error";
    HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;

    String detailMessage = ex.getLocalizedMessage();

    if (detailMessage == null) {
        bodyOfResponse = "Internal Server Error";
        httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;

    } else if (detailMessage.contains("evaluation version")) {

        bodyOfResponse = "Please upgrade to paid license to avail this feature. \n Internal Error - "
                + ex.getMessage();//from   ww w . java  2  s  . co  m
        httpStatus = HttpStatus.PAYMENT_REQUIRED;

    } else {
        bodyOfResponse = ex.getMessage();
        httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;

    }

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.TEXT_PLAIN);

    return handleExceptionInternal(ex, bodyOfResponse, headers, httpStatus, request);
}

From source file:com.ewerk.prototype.api.GlobalErrorHandlerTest.java

@Test
public void testHandleException() {
    GlobalErrorHandler handler = new GlobalErrorHandler();
    final ResponseEntity<String> responseEntity = handler.handleException(new RuntimeException("Test"));
    assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
    assertThat(responseEntity.getBody()).isEqualTo("Test");
}