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);
}
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);
}
Aggregations