3 liens privés
Customize 500 error page
<!-- Prior to Servlet 3.0 define either an error-code or an exception-type but not both -->
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error</location>
</error-page>
Controller :
@Controller
class CustomErrorController {
@RequestMapping("error")
public String customError(HttpServletRequest request, HttpServletResponse response, Model model) {
// retrieve some useful information from the request
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
// String servletName = (String) request.getAttribute("javax.servlet.error.servlet_name");
String exceptionMessage = getExceptionMessage(throwable, statusCode);
String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri");
if (requestUri == null) {
requestUri = "Unknown";
}
String message = MessageFormat.format("{0} returned for {1} with message {3}",
statusCode, requestUri, exceptionMessage
);
model.addAttribute("errorMessage", message);
return "customError";
}