From fb29a3c318ffc49212617a1fbe17e28da476ac0f Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 15 Apr 2014 07:23:41 -0700 Subject: [PATCH] Expand Error Handling section in docs a bit Fixes gh-513 --- .../asciidoc/production-ready-features.adoc | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index 06a8b1d140..42d52eed89 100644 --- a/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -740,10 +740,41 @@ if needed. [[production-ready-error-handling]] == Error Handling -Spring Boot Actuator provides an `/error` mapping by default that handles all errors in a -sensible way. If you want more specific error pages for some conditions, the embedded -servlet containers support a uniform Java DSL for customizing the error handling. +Spring Boot Actuator provides an `/error` mapping by default that +handles all errors in a sensible way, and it is registered as a +"global" error page in the servlet container. For machine clients it +will produce a JSON response with details of the error, the HTTP +status and the exception message. For browser clients there is a +"whitelabel" error view that renders the same data in HTML format (to +customize it just add a `View` that resolves to ``error''). + +If you want more specific error +pages for some conditions, the embedded servlet containers support a +uniform Java DSL for customizing the error handling. For example: + +[source,java,indent=0,subs="verbatim,quotes,attributes"] +---- + @Bean + public EmbeddedServletContainerCustomizer containerCustomizer(){ + return new MyCustomizer(); + } + + // ... + + private static class MyCustomizer implements EmbeddedServletContainerCustomizer { + + @Override + public void customize(ConfigurableEmbeddedServletContainer factory) { + factory.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400")); + } + + } +---- + + +You can also use regular Spring MVC features like http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-exception-handlers[`@ExceptionHandler` +methods] and http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-controller-advice[`@ControllerAdvice`]. [[production-ready-process-monitoring]]