Created
September 24, 2018 04:54
-
-
Save sampathsl/11975a7d25e7723726acded0409169e5 to your computer and use it in GitHub Desktop.
Spring boot overriding the default white label error page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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