Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sampathsl
Created September 24, 2018 05:01
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/46349d127aff7dca643fc58af5b29c7d to your computer and use it in GitHub Desktop.
Save sampathsl/46349d127aff7dca643fc58af5b29c7d to your computer and use it in GitHub Desktop.
Spring boot overriding the white label error template
@Controller
public class CommonErrorController implements ErrorController {
@Autowired private ErrorAttributes errorAttributes;
public void setErrorAttributes(ErrorAttributes errorAttributes) {
this.errorAttributes = errorAttributes;
}
@RequestMapping(value = "error")
@ResponseBody
public ExceptionResponse error(WebRequest webRequest, HttpServletResponse response) {
return new ExceptionResponse(response.getStatus(), getErrorAttributes(webRequest));
}
@Override
public String getErrorPath() {
return "error";
}
private Map<String, Object> getErrorAttributes(WebRequest webRequest) {
Map<String, Object> errorMap = new HashMap<>();
errorMap.putAll(errorAttributes.getErrorAttributes(webRequest, false));
return errorMap;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment