if(!method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST) && !method.equals(HttpMethods.HEAD)) {
return;
}
final String message;
final ErrorCode error;
final String note;
if(response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
message = "Path not found";
if (!request.getRequestURI().contains("/v1/")) {
note = "try including /v1/ in the path";
} else {
note = null;
}
error = ErrorCode.MALFORMED_REQUEST;
} else {
if (response instanceof Response) {
note = ((Response)response).getReason();
} else {
note = null;
}
message = HttpStatus.getMessage(response.getStatus());
error = ErrorCode.INTERNAL_ERROR;
}
response.setContentType(MediaType.APPLICATION_JSON);
response.setHeader(HttpHeaders.CACHE_CONTROL, getCacheControl());
StringBuilder builder = new StringBuilder();
RestResponseBuilder.formatJsonError(builder, error.getFormattedValue(), message, note);
builder.append('\n');
response.setContentLength(builder.length());
OutputStream out = response.getOutputStream();
out.write(builder.toString().getBytes());