Search in sources :

Example 1 with RestErrorModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.RestErrorModel in project ma-core-public by infiniteautomation.

the class RestExceptionHandler method handleExceptionInternal.

/* (non-Javadoc)
     * @see org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler#handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.context.request.WebRequest)
     */
@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) {
    // To strip off the double messages generated by this...
    if (ex instanceof NestedRuntimeException)
        ex = (Exception) ((NestedRuntimeException) ex).getMostSpecificCause();
    LOG.error(ex.getMessage(), ex);
    RestErrorModel error = new RestErrorModel(ex);
    headers.set("Messages", "error");
    headers.set("Errors", ex.getMessage());
    headers.setContentType(MediaType.APPLICATION_JSON);
    if (body == null)
        body = error;
    return super.handleExceptionInternal(ex, body, headers, status, request);
}
Also used : NestedRuntimeException(org.springframework.core.NestedRuntimeException) RestErrorModel(com.serotonin.m2m2.web.mvc.rest.v1.model.RestErrorModel) NoSuchRequestHandlingMethodException(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) HttpMessageNotWritableException(org.springframework.http.converter.HttpMessageNotWritableException) NoHandlerFoundException(org.springframework.web.servlet.NoHandlerFoundException) MissingServletRequestPartException(org.springframework.web.multipart.support.MissingServletRequestPartException) BindException(org.springframework.validation.BindException) ConversionNotSupportedException(org.springframework.beans.ConversionNotSupportedException) NestedRuntimeException(org.springframework.core.NestedRuntimeException) CSVException(com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVException) MissingServletRequestParameterException(org.springframework.web.bind.MissingServletRequestParameterException) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) ServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException) TypeMismatchException(org.springframework.beans.TypeMismatchException) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) HttpMediaTypeNotSupportedException(org.springframework.web.HttpMediaTypeNotSupportedException) HttpRequestMethodNotSupportedException(org.springframework.web.HttpRequestMethodNotSupportedException) HttpMediaTypeNotAcceptableException(org.springframework.web.HttpMediaTypeNotAcceptableException)

Example 2 with RestErrorModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.RestErrorModel in project ma-core-public by infiniteautomation.

the class RestExceptionHandler method handleMangoError.

@ExceptionHandler({ NoSupportingModelException.class, CSVException.class, ModelNotFoundException.class })
protected ResponseEntity<Object> handleMangoError(Exception e, WebRequest request) {
    RestErrorModel error = new RestErrorModel(e);
    HttpHeaders headers = new HttpHeaders();
    headers.set("Messages", "error");
    headers.set("Errors", e.getMessage());
    headers.setContentType(MediaType.APPLICATION_JSON);
    return handleExceptionInternal(e, error, headers, HttpStatus.INTERNAL_SERVER_ERROR, request);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RestErrorModel(com.serotonin.m2m2.web.mvc.rest.v1.model.RestErrorModel) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseEntityExceptionHandler(org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)

Aggregations

RestErrorModel (com.serotonin.m2m2.web.mvc.rest.v1.model.RestErrorModel)2 CSVException (com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVException)1 ConversionNotSupportedException (org.springframework.beans.ConversionNotSupportedException)1 TypeMismatchException (org.springframework.beans.TypeMismatchException)1 NestedRuntimeException (org.springframework.core.NestedRuntimeException)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpMessageNotReadableException (org.springframework.http.converter.HttpMessageNotReadableException)1 HttpMessageNotWritableException (org.springframework.http.converter.HttpMessageNotWritableException)1 BindException (org.springframework.validation.BindException)1 HttpMediaTypeNotAcceptableException (org.springframework.web.HttpMediaTypeNotAcceptableException)1 HttpMediaTypeNotSupportedException (org.springframework.web.HttpMediaTypeNotSupportedException)1 HttpRequestMethodNotSupportedException (org.springframework.web.HttpRequestMethodNotSupportedException)1 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)1 MissingServletRequestParameterException (org.springframework.web.bind.MissingServletRequestParameterException)1 ServletRequestBindingException (org.springframework.web.bind.ServletRequestBindingException)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1 MissingServletRequestPartException (org.springframework.web.multipart.support.MissingServletRequestPartException)1 NoHandlerFoundException (org.springframework.web.servlet.NoHandlerFoundException)1 ResponseEntityExceptionHandler (org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)1 NoSuchRequestHandlingMethodException (org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException)1