Skip to content

Commit

Permalink
doc(howTo.pages.actuator): add notes about whiteLabelErrorPage
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredo-toledano committed Jul 2, 2024
1 parent 4cef1bc commit c247fea
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@ Spring Boot Actuator

[[howto.actuator.customize-whitelabel-error-page]]
== Customize the '`whitelabel`' Error Page
* TODO:
Spring Boot installs a '`whitelabel`' error page that you see in a browser client if you encounter a server error (machine clients consuming JSON and other media types should see a sensible response with the right error code).

NOTE: Set `server.error.whitelabel.enabled=false` to switch the default error page off.
Doing so restores the default of the servlet container that you are using.
Note that Spring Boot still tries to resolve the error view, so you should probably add your own error page rather than disabling it completely.

Overriding the error page with your own depends on the templating technology that you use.
For example, if you use Thymeleaf, you can add an `error.html` template.
If you use FreeMarker, you can add an `error.ftlh` template.
In general, you need a `View` that resolves with a name of `error` or a `@Controller` that handles the `/error` path.
Unless you replaced some of the default configuration, you should find a `BeanNameViewResolver` in your `ApplicationContext`, so a `@Bean` named `error` would be one way of doing that.
See {code-spring-boot-autoconfigure-src}/web/servlet/error/ErrorMvcAutoConfiguration.java[`ErrorMvcAutoConfiguration`] for more options.

See also the section on xref:reference:web/servlet.adoc#web.servlet.spring-mvc.error-handling[] for details of how to register handlers in the servlet container.
* '`whitelabel`' error page
** installed by Spring Boot
** if you encounter a server error &
*** browser client -> '`whitelabel`' error page displayed
*** machine clients / consuming JSON and other media types -> sensible response / right error code
** if you set `server.error.whitelabel.enabled=false` -> 👁️switch off the default error page 👁️ ->
*** you must handle it / exists `BeanNameViewResolver` in your `ApplicationContext` (== `@Bean` named `error`)
**** Reason: 🧠 Spring Boot still tries to resolve the error view 🧠
**** overriding the error -- via -- templating technology
***** Thymeleaf -- adding an -- `error.html` template
***** FreeMarker -- adding an -- `error.ftlh` template
**** `View` / -- resolves with a name of -- `error` OR
**** `@Controller` / handles the `/error` path
**** Check
***** {code-spring-boot-autoconfigure-src}/web/servlet/error/ErrorMvcAutoConfiguration.java[`ErrorMvcAutoConfiguration`] for more options
***** xref:reference:web/servlet.adoc#web.servlet.spring-mvc.error-handling[] -- how to register handlers in the servlet container?



[[howto.actuator.customizing-sanitization]]
== Customizing Sanitization

* TODO:
To take control over the sanitization, define a `SanitizingFunction` bean.
The `SanitizableData` with which the function is called provides access to the key and value as well as the `PropertySource` from which they came.
This allows you to, for example, sanitize every value that comes from a particular property source.
Expand Down

0 comments on commit c247fea

Please sign in to comment.