From 27d3658eb03f7f0f01443692c1972e996333664a Mon Sep 17 00:00:00 2001 From: Mukesh Katariya Date: Fri, 13 Sep 2019 17:43:53 +0530 Subject: [PATCH] refactor: combine Thymeleaf error pages into one. Fix #1119 --- .../ru/mystamps/web/config/MvcConfig.java | 2 +- .../web/feature/site/ErrorController.java | 7 +- .../ru/mystamps/i18n/Messages.properties | 6 +- .../ru/mystamps/i18n/Messages_ru.properties | 6 +- src/main/webapp/WEB-INF/views/error/403.html | 77 ------------------- src/main/webapp/WEB-INF/views/error/404.html | 77 ------------------- .../error/{500.html => status-code.html} | 24 +++++- 7 files changed, 28 insertions(+), 171 deletions(-) delete mode 100644 src/main/webapp/WEB-INF/views/error/403.html delete mode 100644 src/main/webapp/WEB-INF/views/error/404.html rename src/main/webapp/WEB-INF/views/error/{500.html => status-code.html} (77%) diff --git a/src/main/java/ru/mystamps/web/config/MvcConfig.java b/src/main/java/ru/mystamps/web/config/MvcConfig.java index ab9adc1c71..fc5de48dbb 100755 --- a/src/main/java/ru/mystamps/web/config/MvcConfig.java +++ b/src/main/java/ru/mystamps/web/config/MvcConfig.java @@ -105,7 +105,7 @@ public void configureDefaultServletHandling(DefaultServletHandlerConfigurer conf @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController(AccountUrl.AUTHENTICATION_PAGE); - registry.addViewController(SiteUrl.FORBIDDEN_PAGE); + registry.addViewController(SiteUrl.FORBIDDEN_PAGE).setViewName("error/status-code"); } @Override diff --git a/src/main/java/ru/mystamps/web/feature/site/ErrorController.java b/src/main/java/ru/mystamps/web/feature/site/ErrorController.java index 0cc3eeb59d..0f496477b3 100644 --- a/src/main/java/ru/mystamps/web/feature/site/ErrorController.java +++ b/src/main/java/ru/mystamps/web/feature/site/ErrorController.java @@ -37,7 +37,7 @@ public class ErrorController { private final SiteService siteService; @RequestMapping(SiteUrl.NOT_FOUND_PAGE) - public void notFound( + public String notFound( HttpServletRequest request, @CurrentUser Integer currentUserId, // CheckStyle: ignore LineLength for next 1 line @@ -50,10 +50,12 @@ public void notFound( String method = request.getMethod(); siteService.logAboutAbsentPage(page, method, currentUserId, ip, referer, agent); + + return "error/status-code"; } @RequestMapping(SiteUrl.INTERNAL_ERROR_PAGE) - public void internalError( + public String internalError( // CheckStyle: ignore LineLength for next 3 lines @RequestAttribute(name = RequestDispatcher.ERROR_EXCEPTION_TYPE, required = false) Class exceptionType, @RequestAttribute(name = RequestDispatcher.ERROR_EXCEPTION, required = false) Exception exception, @@ -69,6 +71,7 @@ public void internalError( exception ); } + return "error/status-code"; } private static Object getNameOrAsIs(Class clazz) { diff --git a/src/main/resources/ru/mystamps/i18n/Messages.properties b/src/main/resources/ru/mystamps/i18n/Messages.properties index a40cd28dd4..af4ad2ebd9 100644 --- a/src/main/resources/ru/mystamps/i18n/Messages.properties +++ b/src/main/resources/ru/mystamps/i18n/Messages.properties @@ -96,15 +96,11 @@ t_password_again = Retype password t_activation_key = Activation key t_register = Register -# error/403.html +# error/status-code.html t_403_title = 403: forbidden t_403_description = Forbidden - -# error/404.html t_404_title = 404: page not found t_404_description = Requested page{0}not found - -# error/500.html t_500_title = 500: internal server error t_500_description = Internal{0}server error diff --git a/src/main/resources/ru/mystamps/i18n/Messages_ru.properties b/src/main/resources/ru/mystamps/i18n/Messages_ru.properties index 66e52d2a18..cbdbf10569 100644 --- a/src/main/resources/ru/mystamps/i18n/Messages_ru.properties +++ b/src/main/resources/ru/mystamps/i18n/Messages_ru.properties @@ -96,15 +96,11 @@ t_password_again = Пароль (ещё раз) t_activation_key = Код активации t_register = Зарегистрироваться -# error/403.html +# error/status-code.html t_403_title = 403: доступ запрещён t_403_description = Доступ запрещён - -# error/404.html t_404_title = 404: страница не найдена t_404_description = Запрашиваемая страница{0}не найдена - -# error/500.html t_500_title = 500: внутренняя ошибка сервера t_500_description = Внутренняя{0}ошибка сервера diff --git a/src/main/webapp/WEB-INF/views/error/403.html b/src/main/webapp/WEB-INF/views/error/403.html deleted file mode 100644 index b70229fda2..0000000000 --- a/src/main/webapp/WEB-INF/views/error/403.html +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - 403: forbidden - - - - - -
- - -
-
-

- 403 -

-

- Forbidden -

-
-
- -
- -
-
- - - - - - diff --git a/src/main/webapp/WEB-INF/views/error/404.html b/src/main/webapp/WEB-INF/views/error/404.html deleted file mode 100644 index 3ca44bc822..0000000000 --- a/src/main/webapp/WEB-INF/views/error/404.html +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - 404: page not found - - - - - -
- - -
-
-

- 404 -

-

- Requested page
not found -

-
-
- -
- -
-
- - - - - - diff --git a/src/main/webapp/WEB-INF/views/error/500.html b/src/main/webapp/WEB-INF/views/error/status-code.html similarity index 77% rename from src/main/webapp/WEB-INF/views/error/500.html rename to src/main/webapp/WEB-INF/views/error/status-code.html index 2cbd3ef313..1244e014ee 100644 --- a/src/main/webapp/WEB-INF/views/error/500.html +++ b/src/main/webapp/WEB-INF/views/error/status-code.html @@ -8,7 +8,13 @@ - 500: internal server error + + 500: internal server error + @@ -53,11 +59,21 @@
-

+

500

-

- Internal
server error +

+ + + Internal
server error +