Skip to content

Combine Themyleaf error pages #1122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/ru/mystamps/web/config/MvcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -69,6 +71,7 @@ public void internalError(
exception
);
}
return "error/status-code";
}

private static Object getNameOrAsIs(Class<?> clazz) {
Expand Down
6 changes: 1 addition & 5 deletions src/main/resources/ru/mystamps/i18n/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}ошибка сервера

Expand Down
77 changes: 0 additions & 77 deletions src/main/webapp/WEB-INF/views/error/403.html

This file was deleted.

77 changes: 0 additions & 77 deletions src/main/webapp/WEB-INF/views/error/404.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="robots" content="noindex" />
<title th:text="#{t_500_title}">500: internal server error</title>
<!--/*/
<th:block th:switch="${#response.status}">
<title th:case="'403'" th:text="#{t_403_title}">403: forbidden</title>
<title th:case="'404'" th:text="#{t_404_title}">404: page not found</title>
/*/-->
<title th:case="'500'" th:text="#{t_500_title}">500: internal server error</title>
<!--/*/ </th:block> /*/-->
<link rel="shortcut icon" type="image/x-icon" href="../../../favicon.ico" th:href="${FAVICON_ICO}" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" th:href="${BOOTSTRAP_CSS}" />
<link rel="stylesheet" href="../../static/styles/main.css" th:href="${MAIN_CSS}" />
Expand Down Expand Up @@ -53,11 +59,21 @@

<div class="row text-center">
<div id="content" class="col-sm-12">
<h1 id="error-code">
<h1 id="error-code" th:text="${#response.status}">
500
</h1>
<h4 id="error-msg" th:utext="#{t_500_description('&lt;br /&gt;')}">
Internal<br />server error
<h4 id="error-msg" th:switch="${#response.status}">
<!--/*/
<span th:case="'403'" th:text="#{t_403_description}" th:remove="tag">
Forbidden
</span>
<span th:case="'404'" th:utext="#{t_404_description('&lt;br /&gt;')}" th:remove="tag">
Requested page<br />not found
</span>
/*/-->
<span th:case="*" th:utext="#{t_500_description('&lt;br /&gt;')}" th:remove="tag">
Internal<br />server error
</span>
</h4>
</div>
</div>
Expand Down