Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.