From 48a70669c5a0fcb0cf3e4523be78b4e6435ae564 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 6 Apr 2018 11:03:47 +0300 Subject: [PATCH] style pages --- .../controllers/MyErrorController.java | 26 ++++++++++--------- .../main/resources/templates/error-404.html | 13 +++++++--- .../main/resources/templates/error-500.html | 15 ++++++++--- .../src/main/resources/templates/error.html | 13 ++++++++-- .../src/main/resources/templates/index.ftl | 6 ----- 5 files changed, 47 insertions(+), 26 deletions(-) delete mode 100644 spring-boot/src/main/resources/templates/index.ftl 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 d0c548e7bbad..caa335ed23a1 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 MyErrorController() {} @RequestMapping(value = "/error") public String handleError(HttpServletRequest request) { - - Integer statusCode = - Integer.valueOf(request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE).toString()); - - if(statusCode == HttpStatus.NOT_FOUND.value()) { - return "error-404"; - } - else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) { - return "error-500"; - } - else { - return "error"; + + 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"; } @Override diff --git a/spring-boot/src/main/resources/templates/error-404.html b/spring-boot/src/main/resources/templates/error-404.html index 3d3adaefa6b6..cf680325960a 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 @@ + + + + -

Sorry we couldn't find the resource you are looking for

-Go Home +
+
+

Sorry, we couldn't find the page you were looking for.

+

Go Home

+
- + \ No newline at end of file diff --git a/spring-boot/src/main/resources/templates/error-500.html b/spring-boot/src/main/resources/templates/error-500.html index 979dd7676484..5ddf45822909 100644 --- a/spring-boot/src/main/resources/templates/error-500.html +++ b/spring-boot/src/main/resources/templates/error-500.html @@ -1,7 +1,16 @@ + + + + -

Oops! We spilled something but we're fixing it

-Go Home +
+
+

Sorry, something went wrong!

+ +

We're fixing it.

+

Go Home

+
- + \ No newline at end of file diff --git a/spring-boot/src/main/resources/templates/error.html b/spring-boot/src/main/resources/templates/error.html index 26d1a22b6c80..bc517913b207 100644 --- a/spring-boot/src/main/resources/templates/error.html +++ b/spring-boot/src/main/resources/templates/error.html @@ -1,7 +1,16 @@ + + + + -

Something went wrong! Our Engineers are on it temp

-Go Home +
+
+

Something went wrong!

+ +

Our Engineers are on it.

+

Go Home

+
diff --git a/spring-boot/src/main/resources/templates/index.ftl b/spring-boot/src/main/resources/templates/index.ftl deleted file mode 100644 index ce0505006ea4..000000000000 --- a/spring-boot/src/main/resources/templates/index.ftl +++ /dev/null @@ -1,6 +0,0 @@ - - - -

Welcome Home

- -