Skip to content

Instantly share code, notes, and snippets.

@sampathsl
Created September 24, 2018 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sampathsl/11975a7d25e7723726acded0409169e5 to your computer and use it in GitHub Desktop.
Save sampathsl/11975a7d25e7723726acded0409169e5 to your computer and use it in GitHub Desktop.
Spring boot overriding the default white label error page
@Controller
public class CustomErrorController implements ErrorController {
@RequestMapping("/error")
@ResponseBody
public String handleError(HttpServletRequest request) {
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
Exception exception = (Exception) request.getAttribute("javax.servlet.error.exception");
return String.format("<html><body><h2>Sample Error Page</h2><div>Status code: <b>%s</b></div>"
+ "<div>Exception Message: <b>%s</b></div><body></html>",
statusCode, exception==null? "N/A": exception.getMessage());
}
@Override
public String getErrorPath() {
return "/error";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment