Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Spring boot overriding the default white label error page
public class CustomErrorController implements ErrorController {
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());
public String getErrorPath() {
return "/error";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment