Skip to content

Commit 36ad76e

Browse files
committed
fix: show custom error page for 400 Bad Request errors
Fix #1351
1 parent 3862eeb commit 36ad76e

File tree

7 files changed

+29
-0
lines changed

7 files changed

+29
-0
lines changed

Diff for: src/main/java/ru/mystamps/web/config/MvcConfig.java

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public void configureDefaultServletHandling(DefaultServletHandlerConfigurer conf
108108
public void addViewControllers(ViewControllerRegistry registry) {
109109
registry.addViewController(AccountUrl.AUTHENTICATION_PAGE);
110110
registry.addViewController(SiteUrl.FORBIDDEN_PAGE).setViewName("error/status-code");
111+
registry.addViewController(SiteUrl.BAD_REQUEST_PAGE).setViewName("error/status-code");
111112
}
112113

113114
@Override

Diff for: src/main/java/ru/mystamps/web/feature/site/SiteUrl.java

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public final class SiteUrl {
3939
public static final String SITE_EVENTS_PAGE = "/site/events";
4040
public static final String CSP_REPORTS_HANDLER = "/site/csp/reports";
4141

42+
public static final String BAD_REQUEST_PAGE = "/error/400";
4243
public static final String FORBIDDEN_PAGE = "/error/403";
4344
public static final String NOT_FOUND_PAGE = "/error/404";
4445
public static final String INTERNAL_ERROR_PAGE = "/error/500";

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

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class ErrorPagesCustomizer implements ErrorPageRegistrar {
3131
@Override
3232
public void registerErrorPages(ErrorPageRegistry registry) {
3333
registry.addErrorPages(
34+
new ErrorPage(HttpStatus.BAD_REQUEST, SiteUrl.BAD_REQUEST_PAGE),
3435
new ErrorPage(HttpStatus.FORBIDDEN, SiteUrl.FORBIDDEN_PAGE),
3536
new ErrorPage(HttpStatus.NOT_FOUND, SiteUrl.NOT_FOUND_PAGE),
3637
new ErrorPage(RequestRejectedException.class, SiteUrl.NOT_FOUND_PAGE),

Diff for: src/main/resources/ru/mystamps/i18n/Messages.properties

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ t_activation_key = Activation key
9898
t_register = Register
9999

100100
# error/status-code.html
101+
t_400_title = 400: bad request
102+
t_400_description = Bad request
101103
t_403_title = 403: forbidden
102104
t_403_description = Forbidden
103105
t_404_title = 404: page not found

Diff for: src/main/resources/ru/mystamps/i18n/Messages_ru.properties

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ t_activation_key = Код активации
9898
t_register = Зарегистрироваться
9999

100100
# error/status-code.html
101+
t_400_title = 400: некорректный запрос
102+
t_400_description = Некорректный запрос
101103
t_403_title = 403: доступ запрещён
102104
t_403_description = Доступ запрещён
103105
t_404_title = 404: страница не найдена

Diff for: src/main/webapp/WEB-INF/views/error/status-code.html

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<meta name="robots" content="noindex" />
1111
<!--/*/
1212
<th:block th:switch="${#response.status}">
13+
<title th:case="'400'" th:text="#{t_400_title}">400: bad request</title>
1314
<title th:case="'403'" th:text="#{t_403_title}">403: forbidden</title>
1415
<title th:case="'404'" th:text="#{t_404_title}">404: page not found</title>
1516
/*/-->
@@ -64,6 +65,9 @@ <h1 id="error-code" th:text="${#response.status}">
6465
</h1>
6566
<h4 id="error-msg" th:switch="${#response.status}">
6667
<!--/*/
68+
<span th:case="'400'" th:text="#{t_400_description}" th:remove="tag">
69+
Bad request
70+
</span>
6771
<span th:case="'403'" th:text="#{t_403_description}" th:remove="tag">
6872
Forbidden
6973
</span>

Diff for: src/test/robotframework/site/error/misc.robot

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*** Settings ***
2+
Documentation Verify error pages
3+
Library SeleniumLibrary
4+
Suite Setup Before Test Suite
5+
Suite Teardown Close Browser
6+
Force Tags error-page misc
7+
8+
*** Test Cases ***
9+
Client should see a custom page for Bad Request error
10+
Title Should Be 400: bad request
11+
Element Text Should Be id:error-code 400
12+
Element Text Should Be id:error-msg Bad request
13+
14+
*** Keywords ***
15+
Before Test Suite
16+
Open Browser ${SITE_URL}/series/info ${BROWSER}
17+
Register Keyword To Run On Failure Log Source
18+

0 commit comments

Comments
 (0)