Skip to content

Instantly share code, notes, and snippets.

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