Skip to content

Combine Thymeleaf error pages #1119

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

Closed
php-coder opened this issue Sep 8, 2019 · 2 comments · Fixed by #1122
Closed

Combine Thymeleaf error pages #1119

php-coder opened this issue Sep 8, 2019 · 2 comments · Fixed by #1122
Assignees
Labels
estimation/30m Estimated time: 30 minutes refactoring
Milestone

Comments

@php-coder
Copy link
Owner

php-coder commented Sep 8, 2019

We have 3 error pages (src/main/webapp/WEB-INF/views/error/{403,404,500}.html) that nearly identical to each other:

--- 403.html    2019-05-07 18:43:19.988009600 +0100
+++ 500.html    2019-05-07 18:43:19.993828400 +0100
@@ -10,3 +10,3 @@
                <meta name="robots" content="noindex" />
-               <title th:text="#{t_403_title}">403: forbidden</title>
+               <title th:text="#{t_500_title}">500: internal server error</title>
                <link rel="shortcut icon" type="image/x-icon" href="../../../favicon.ico" th:href="${FAVICON_ICO}" />
@@ -56,6 +56,6 @@
                                        <h1 id="error-code">
-                                               403
+                                               500
                                        </h1>
-                                       <h4 id="error-msg" th:text="#{t_403_description}">
-                                               Forbidden
+                                       <h4 id="error-msg" th:utext="#{t_500_description('&lt;br /&gt;')}">
+                                               Internal<br />server error
                                        </h4>

The difference are the following:

  • title
  • error code
  • error message

The task is to combine them into a single page and use condition to find out what eror message/code. Perhaps, we can utilize th:switch/th:case.

See also https://www.thymeleaf.org/doc/articles/springsecurity.html part 3 with an example of that approach. Keep in mind, that our approach will be similar by idea but not literally -- we won't pass error message from controller but will decided what message to show dependig on a reponse status.

@php-coder php-coder added this to the next milestone Sep 8, 2019
@php-coder php-coder modified the milestones: next, 0.4.1 Sep 8, 2019
@mukeshk
Copy link
Contributor

mukeshk commented Sep 12, 2019

Currently ErrorPagesCustomizer - maps to different request - to respective methods in ErrorController.
As per Step#3 of the Article shared. we need to have common exception handler.
Do we need to make changes to ErrorController?

@php-coder
Copy link
Owner Author

Thank you, Mukesh! It's indeed a good question!

Currently ErrorPagesCustomizer - maps to different request - to respective methods in ErrorController.

Yes, ErrorPagesCustomizer maps errors to URLs and these URLs are served by ErrorController (all expect FORBIDDEN_PAGE).

As per Step#3 of the Article shared. we need to have common exception handler.

As far I see we don't need a common exception handler, we might have many exception handling mechanisms but all of them should use a single view.

Do we need to make changes to ErrorController?

Yes, we need to modify both methods to return a String type (instead of void) and return name of a view file (let's name it "error/status-code").

In order to modify FORBIDDEN_PAGE, we need to change

registry.addViewController(SiteUrl.FORBIDDEN_PAGE);

mukeshk added a commit to mukeshk/mystamps that referenced this issue Sep 13, 2019
mukeshk added a commit to mukeshk/mystamps that referenced this issue Sep 13, 2019
mukeshk added a commit to mukeshk/mystamps that referenced this issue Sep 13, 2019
mukeshk added a commit to mukeshk/mystamps that referenced this issue Sep 13, 2019
mukeshk added a commit to mukeshk/mystamps that referenced this issue Sep 14, 2019
mukeshk added a commit to mukeshk/mystamps that referenced this issue Sep 15, 2019
mukeshk added a commit to mukeshk/mystamps that referenced this issue Sep 15, 2019
mukeshk added a commit to mukeshk/mystamps that referenced this issue Sep 16, 2019
mukeshk added a commit to mukeshk/mystamps that referenced this issue Sep 16, 2019
mukeshk added a commit to mukeshk/mystamps that referenced this issue Sep 17, 2019
@php-coder php-coder added the estimation/30m Estimated time: 30 minutes label Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
estimation/30m Estimated time: 30 minutes refactoring
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants