Skip to content

Commit bcba306

Browse files
committed
combine themeleaf error pages
Fix #1119
1 parent 253655a commit bcba306

File tree

8 files changed

+24
-171
lines changed

8 files changed

+24
-171
lines changed

src/main/java/ru/mystamps/web/config/MvcConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void configureDefaultServletHandling(DefaultServletHandlerConfigurer conf
105105
@Override
106106
public void addViewControllers(ViewControllerRegistry registry) {
107107
registry.addViewController(AccountUrl.AUTHENTICATION_PAGE);
108-
registry.addViewController(SiteUrl.FORBIDDEN_PAGE);
108+
registry.addViewController("/error/status-code");
109109
}
110110

111111
@Override

src/main/java/ru/mystamps/web/feature/site/ErrorController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ErrorController {
3737
private final SiteService siteService;
3838

3939
@RequestMapping(SiteUrl.NOT_FOUND_PAGE)
40-
public void notFound(
40+
public String notFound(
4141
HttpServletRequest request,
4242
@CurrentUser Integer currentUserId,
4343
// CheckStyle: ignore LineLength for next 1 line
@@ -50,10 +50,12 @@ public void notFound(
5050
String method = request.getMethod();
5151

5252
siteService.logAboutAbsentPage(page, method, currentUserId, ip, referer, agent);
53+
54+
return "error/status-code";
5355
}
5456

5557
@RequestMapping(SiteUrl.INTERNAL_ERROR_PAGE)
56-
public void internalError(
58+
public String internalError(
5759
// CheckStyle: ignore LineLength for next 3 lines
5860
@RequestAttribute(name = RequestDispatcher.ERROR_EXCEPTION_TYPE, required = false) Class<?> exceptionType,
5961
@RequestAttribute(name = RequestDispatcher.ERROR_EXCEPTION, required = false) Exception exception,
@@ -69,6 +71,7 @@ public void internalError(
6971
exception
7072
);
7173
}
74+
return "error/status-code";
7275
}
7376

7477
private static Object getNameOrAsIs(Class<?> clazz) {

src/main/java/ru/mystamps/web/support/spring/boot/ErrorPagesCustomizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class ErrorPagesCustomizer implements ErrorPageRegistrar {
3131
@Override
3232
public void registerErrorPages(ErrorPageRegistry registry) {
3333
registry.addErrorPages(
34-
new ErrorPage(HttpStatus.FORBIDDEN, SiteUrl.FORBIDDEN_PAGE),
34+
new ErrorPage(HttpStatus.FORBIDDEN, "/error/status-code"),
3535
new ErrorPage(HttpStatus.NOT_FOUND, SiteUrl.NOT_FOUND_PAGE),
3636
new ErrorPage(RequestRejectedException.class, SiteUrl.NOT_FOUND_PAGE),
3737
new ErrorPage(Exception.class, SiteUrl.INTERNAL_ERROR_PAGE)

src/main/resources/ru/mystamps/i18n/Messages.properties

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,11 @@ t_password_again = Retype password
9696
t_activation_key = Activation key
9797
t_register = Register
9898

99-
# error/403.html
99+
# error/status-code.html
100100
t_403_title = 403: forbidden
101101
t_403_description = Forbidden
102-
103-
# error/404.html
104102
t_404_title = 404: page not found
105103
t_404_description = Requested page{0}not found
106-
107-
# error/500.html
108104
t_500_title = 500: internal server error
109105
t_500_description = Internal{0}server error
110106

src/main/resources/ru/mystamps/i18n/Messages_ru.properties

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,11 @@ t_password_again = Пароль (ещё раз)
9696
t_activation_key = Код активации
9797
t_register = Зарегистрироваться
9898

99-
# error/403.html
99+
# error/status-code.html
100100
t_403_title = 403: доступ запрещён
101101
t_403_description = Доступ запрещён
102-
103-
# error/404.html
104102
t_404_title = 404: страница не найдена
105103
t_404_description = Запрашиваемая страница{0}не найдена
106-
107-
# error/500.html
108104
t_500_title = 500: внутренняя ошибка сервера
109105
t_500_description = Внутренняя{0}ошибка сервера
110106

src/main/webapp/WEB-INF/views/error/403.html

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/main/webapp/WEB-INF/views/error/404.html

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/main/webapp/WEB-INF/views/error/500.html renamed to src/main/webapp/WEB-INF/views/error/status-code.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
99
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
1010
<meta name="robots" content="noindex" />
11-
<title th:text="#{t_500_title}">500: internal server error</title>
11+
<!--/*/ <th:block th:switch="${#response.status}">
12+
<title th:case="'403'" th:text="#{t_403_title}">403: forbidden</title>
13+
<title th:case="'404'" th:text="#{t_404_title}">404: page not found</title> /*/-->
14+
<title th:case="'500'" th:text="#{t_500_title}">500: internal server error</title>
15+
<!--/*/ </th:block> /*/-->
1216
<link rel="shortcut icon" type="image/x-icon" href="../../../favicon.ico" th:href="${FAVICON_ICO}" />
1317
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" th:href="${BOOTSTRAP_CSS}" />
1418
<link rel="stylesheet" href="../../static/styles/main.css" th:href="${MAIN_CSS}" />
@@ -53,12 +57,20 @@
5357

5458
<div class="row text-center">
5559
<div id="content" class="col-sm-12">
56-
<h1 id="error-code">
60+
<h1 id="error-code" th:text="${#response.status}">
5761
500
5862
</h1>
59-
<h4 id="error-msg" th:utext="#{t_500_description('&lt;br /&gt;')}">
63+
<!--/*/ <th:block th:switch="${#response.status}">
64+
<h4 id="error-msg" th:case="'403'" th:text="#{t_403_description}">
65+
Forbidden
66+
</h4>
67+
<h4 id="error-msg" th:case="'404'" th:utext="#{t_404_description('&lt;br /&gt;')}">
68+
Requested page<br />not found
69+
</h4> /*/-->
70+
<h4 id="error-msg" th:case="'500'" th:utext="#{t_500_description('&lt;br /&gt;')}">
6071
Internal<br />server error
6172
</h4>
73+
<!--/*/ </th:block> /*/-->
6274
</div>
6375
</div>
6476

0 commit comments

Comments
 (0)