Created
September 24, 2018 05:01
-
-
Save sampathsl/46349d127aff7dca643fc58af5b29c7d to your computer and use it in GitHub Desktop.
Spring boot overriding the white label error template
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 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