Question
Customizing the error page based on the status instead of Tomcat default page with springboot
Not able to redirect the error in the custom page.
Configuration:
server:
error:
whitelabel:
enabled: false
path: /error
spring:
web:
resources:
add-mappings: false
@RestController
@RequiredArgsConstructor
public class CustomErrorController implements ErrorController {
private static final String PATH = "/error";
@RequestMapping("/error")
public String handleError(HttpServletRequest request) {
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
if (status != null) {
Integer statusCode = Integer.valueOf(status.toString());
if (statusCode == HttpStatus.NOT_FOUND.value()) {
return "error-404";
} else if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) {
return "error-500";
}
}
return "error";
}
}
4 29
4