use of org.n52.web.exception.ExceptionResponse in project series-rest-api by 52North.
the class BaseController method writeExceptionResponse.
private void writeExceptionResponse(WebException e, HttpServletResponse response, HttpStatus status) {
final String logMessage = "An exception occured.";
if (status == HttpStatus.INTERNAL_SERVER_ERROR) {
LOGGER.error(logMessage, e);
} else {
LOGGER.debug(logMessage, e);
}
// TODO consider using a 'suppress_response_codes=true' parameter and always return 200 OK
response.setStatus(status.value());
response.setContentType(MimeType.APPLICATION_JSON.getMimeType());
ObjectMapper objectMapper = createObjectMapper();
ObjectWriter writer = objectMapper.writerFor(ExceptionResponse.class);
ExceptionResponse exceptionResponse = ExceptionResponse.createExceptionResponse(e, status);
try (OutputStream outputStream = response.getOutputStream()) {
writer.writeValue(outputStream, exceptionResponse);
} catch (IOException ioe) {
LOGGER.error("Could not process error message.", ioe);
}
}
Aggregations