use of org.springframework.web.bind.annotation.ExceptionHandler in project rhino by PLOS.
the class RestController method reportClientError.
/**
* Report an error condition to the REST client. The brief error message is sent as the response body, with the
* response code specified when the exception object was created. The stack trace is not included because we generally
* expect the client to fix the error with a simple change to input.
*
* @param e the exception that Spring wants to handle
* @return the RESTful response body
*/
@ExceptionHandler(RestClientException.class)
public ResponseEntity<String> reportClientError(RestClientException e) {
HttpStatus status = e.getResponseStatus();
log.info("Reporting error to client (" + status + ")", e);
String message = e.getMessage().trim() + '\n';
return respondWithPlainText(message, status);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project rhino by PLOS.
the class RestController method reportServerError.
/**
* Display a server-side error to the rest client. This is meant generally to handle bugs and configuration errors.
* Because this is assumed to be caused by programmer error, the stack trace is sent in the request body.
*
* @param e the exception that Spring wants to handle
* @return the RESTful response body
*/
@ExceptionHandler(Exception.class)
public ResponseEntity<String> reportServerError(Exception e) {
log.error("Exception from controller", e);
StringWriter report = new StringWriter();
e.printStackTrace(new PrintWriter(report));
return respondWithPlainText(report.toString(), HttpStatus.INTERNAL_SERVER_ERROR);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project chassis by Kixeye.
the class HttpExceptionHandler method defaultErrorHandler.
@ExceptionHandler(Exception.class)
@ResponseBody
public ServiceError defaultErrorHandler(HttpServletRequest request, HttpServletResponse response, Exception ex) throws Exception {
ServiceError error = ExceptionServiceErrorMapper.mapException(ex);
switch(error.code) {
case ExceptionServiceErrorMapper.UNKNOWN_ERROR_CODE:
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
logger.error("Unexpected error", ex);
break;
case ExceptionServiceErrorMapper.VALIDATION_ERROR_CODE:
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
if (logger.isDebugEnabled()) {
logger.debug("Validation exception", ex);
}
break;
case ExceptionServiceErrorMapper.SECURITY_ERROR_CODE:
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
if (logger.isDebugEnabled()) {
logger.debug("Security exception", ex);
}
break;
default:
if (ex instanceof HttpServiceException) {
HttpServiceException httpEx = (HttpServiceException) ex;
response.setStatus(httpEx.httpResponseCode);
}
logger.warn("Service exception", ex);
break;
}
return error;
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project geode by apache.
the class ExceptionHandlingAdvice method handleExc.
@ExceptionHandler(IOException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public void handleExc(IOException ext) {
// write errors
StringWriter swBuffer = new StringWriter();
PrintWriter prtWriter = new PrintWriter(swBuffer);
ext.printStackTrace(prtWriter);
logger.fatal("IOException Details : {}\n", swBuffer);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project geode by apache.
the class BaseControllerAdvice method handleException.
/**
* Handles any Exception thrown by a REST API web service endpoint, HTTP request handler method.
* <p/>
*
* @param cause the Exception causing the error.
* @return a ResponseEntity with an appropriate HTTP status code (500 - Internal Server Error) and
* HTTP response body containing the stack trace of the Exception.
*/
@ExceptionHandler(Throwable.class)
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String handleException(final Throwable cause) {
final StringWriter stackTraceWriter = new StringWriter();
cause.printStackTrace(new PrintWriter(stackTraceWriter));
final String stackTrace = stackTraceWriter.toString();
if (logger.isDebugEnabled()) {
logger.debug(stackTrace);
}
return convertErrorAsJson(cause.getMessage());
}
Aggregations