diff --git a/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java b/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java index d0c548e7bb..caa335ed23 100644 --- a/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java +++ b/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java @@ -15,19 +15,21 @@ public class MyErrorController implements ErrorController { @RequestMapping(value = "/error") public String handleError(HttpServletRequest request) { + + Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); - Integer statusCode = - Integer.valueOf(request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE).toString()); + 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"; - } - else { - return "error"; + if(statusCode == HttpStatus.NOT_FOUND.value()) { + return "error-404"; + } + else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) { + return "error-500"; + } } + return "error"; } @Override diff --git a/spring-boot/src/main/resources/templates/error-404.html b/spring-boot/src/main/resources/templates/error-404.html index 3d3adaefa6..cf68032596 100644 --- a/spring-boot/src/main/resources/templates/error-404.html +++ b/spring-boot/src/main/resources/templates/error-404.html @@ -1,7 +1,14 @@ +
+ + + -