* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.ServletWebRequest;
* context, including page not found, and redirects the caller to a custom error
* page. The caller is also redirected to this page if a REST controller takes
* an uncaught exception.
* context, including page not found, and redirects the caller to a custom error
* page. The caller is also redirected to this page if a REST controller takes
* an uncaught exception.
* If trace is requested via request parameter ("?trace=true") and available,
* adds stack trace information to the standard JSON error response.
* If trace is requested via request parameter ("?trace=true") and available,
* adds stack trace information to the standard JSON error response.
* https://stackoverflow.com/questions/25356781/spring-boot-remove-whitelabel-error-page
* https://www.baeldung.com/spring-boot-custom-error-page
*/
* https://stackoverflow.com/questions/25356781/spring-boot-remove-whitelabel-error-page
* https://www.baeldung.com/spring-boot-custom-error-page
*/
@RequestMapping(value = SimpleErrorController.ERROR_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
public class SimpleErrorController implements ErrorController {
@RequestMapping(value = SimpleErrorController.ERROR_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
public class SimpleErrorController implements ErrorController {
- @Autowired
- public SimpleErrorController(ErrorAttributes errorAttributes) {
- this.errorAttributes = errorAttributes;
- }
+ @Autowired
+ public SimpleErrorController(ErrorAttributes errorAttributes) {
+ this.errorAttributes = errorAttributes;
+ }
- @GetMapping
- public String handleError(HttpServletRequest request) {
- ServletWebRequest servletWebRequest = new ServletWebRequest(request);
- Throwable t = errorAttributes.getError(servletWebRequest);
- if (t != null)
- logger.warn("handleError", t);
- Map<String, Object> attributes = errorAttributes.getErrorAttributes(servletWebRequest, true);
- attributes.forEach((attribute, value) -> {
- logger.warn("handleError: {} -> {}", attribute, value);
- });
- // Return the name of the page INCLUDING suffix, which I guess is a "view" name.
- // Just "error" is not enough, but don't seem to need a ModelAndView object.
- return "error.html";
- }
+ @GetMapping
+ public String handleError(HttpServletRequest request) {
+ ServletWebRequest servletWebRequest = new ServletWebRequest(request);
+ Throwable t = errorAttributes.getError(servletWebRequest);
+ if (t != null)
+ logger.warn("handleError", t);
+ Map<String, Object> attributes = errorAttributes.getErrorAttributes(servletWebRequest, true);
+ attributes.forEach((attribute, value) -> {
+ logger.warn("handleError: {} -> {}", attribute, value);
+ });
+ // Return the name of the page INCLUDING suffix, which I guess is a "view" name.
+ // Just "error" is not enough, but don't seem to need a ModelAndView object.
+ return "error.html";
+ }