1

I have a SpringBoot v2.3.7.RELEASE with Thymeleaf. I've created this template to see the Errors, but I don't see any exceptions in the source code when there is an exception in the app:

    <div class="jumbotron text-center">

        <h1>Uh-oh! Something Happened!</h1>
        <!--  As we are using Thymeleaf, you might consider using
              ${#httpServletRequest.requestURL}. But that returns the path
              to this error page.  Hence we explicitly add the url to the
              Model in some of the example code. -->
        <p th:if="${url}">
            <b>Page:</b> <span th:text="${url}">Page URL</span>
        </p>

        <p th:if="${timestamp}" id='created'>
            <b>Occurred:</b> <span th:text="${timestamp}">Timestamp</span>
        </p>


        <p>Support may ask you to right click to view page source.</p>

        <!--
          // Hidden Exception Details  - this is not a recommendation, but here is
          // how you hide an exception in the page using Thymeleaf
          -->
        <div th:utext="'&lt;!--'" th:remove="tag"></div>
        <div th:utext="'Failed URL: ' +  ${url}" th:remove="tag">${url}</div>
        <div th:utext="'Exception: ' + ${exception}" th:remove="tag">${exception}</div>
        <ul th:remove="tag">
            <li th:each="ste : ${exception}" th:remove="tag"><span
                    th:utext="${ste}" th:remove="tag">${ste}</span></li>
        </ul>
        <div th:utext="'--&gt;'" th:remove="tag"></div>

    </div>

</div>

and the controller:

@Controller
public class MyErrorController implements ErrorController {

    private final static String PATH = "/error";

    @RequestMapping(PATH)
    public String getErrorPath() {
        return "error/genericError";
    }


}
1

3 Answers 3

3
  1. Spring Boot by default provides /error mapping where all exception/errors are forwarded. In case of Thymeleaf (or other template engines), we can map errors to a global custom template file by name error under src/main/resources/templates/ directory.

  2. enable the stacktrace to be included as expression attribute to the Thymeleaf view:

    server.error.include-stacktrace=always

Sign up to request clarification or add additional context in comments.

Comments

2

In your application.properties, you must disable whitelabel error pages as following

server.error.whitelabel.enabled=false

Comments

0

Check this article: Spring Boot - Custom Error Page in Thymeleaf

Side note: if error message and exception is not showing in the error page you need to do this:

server.error.include-stacktrace = always
server.error.include-exception = true
server.error.include-message = always

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.