Class DefaultErrorWebExceptionHandler

java.lang.Object
org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler
org.springframework.boot.autoconfigure.web.reactive.error.DefaultErrorWebExceptionHandler
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler, org.springframework.web.server.WebExceptionHandler

public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler
Basic global WebExceptionHandler, rendering ErrorAttributes.

More specific errors can be handled either using Spring WebFlux abstractions (e.g. @ExceptionHandler with the annotation model) or by adding RouterFunction to the chain.

This implementation will render error as HTML views if the client explicitly supports that media type. It attempts to resolve error views using well known conventions. Will search for templates and static assets under '/error' using the status code and the status series.

For example, an HTTP 404 will search (in the specific order):

  • '/<templates>/error/404.<ext>'
  • '/<static>/error/404.html'
  • '/<templates>/error/4xx.<ext>'
  • '/<static>/error/4xx.html'
  • '/<templates>/error/error'
  • '/<static>/error/error.html'

If none found, a default "Whitelabel Error" HTML view will be rendered.

If the client doesn't support HTML, the error information will be rendered as a JSON payload.

Since:
2.0.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultErrorWebExceptionHandler(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes, WebProperties.Resources resources, ErrorProperties errorProperties, org.springframework.context.ApplicationContext applicationContext)
    Create a new DefaultErrorWebExceptionHandler instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.springframework.web.reactive.function.server.RequestPredicate
    Predicate that checks whether the current request explicitly support "text/html" media type.
    protected org.springframework.boot.web.error.ErrorAttributeOptions
    getErrorAttributeOptions(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.http.MediaType mediaType)
     
    protected int
    getHttpStatus(Map<String,Object> errorAttributes)
    Get the HTTP error status information from the error map.
    protected org.springframework.web.reactive.function.server.RouterFunction<org.springframework.web.reactive.function.server.ServerResponse>
    getRoutingFunction(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes)
    Create a RouterFunction that can route and handle errors as JSON responses or HTML views.
    protected boolean
    isIncludeBindingErrors(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.http.MediaType produces)
    Determine if the errors attribute should be included.
    protected boolean
    isIncludeMessage(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.http.MediaType produces)
    Determine if the message attribute should be included.
    protected boolean
    isIncludeStackTrace(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.http.MediaType produces)
    Determine if the stacktrace attribute should be included.
    protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse>
    renderErrorResponse(org.springframework.web.reactive.function.server.ServerRequest request)
    Render the error information as a JSON payload.
    protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse>
    renderErrorView(org.springframework.web.reactive.function.server.ServerRequest request)
    Render the error information as an HTML view.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultErrorWebExceptionHandler

      public DefaultErrorWebExceptionHandler(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes, WebProperties.Resources resources, ErrorProperties errorProperties, org.springframework.context.ApplicationContext applicationContext)
      Create a new DefaultErrorWebExceptionHandler instance.
      Parameters:
      errorAttributes - the error attributes
      resources - the resources configuration properties
      errorProperties - the error configuration properties
      applicationContext - the current application context
      Since:
      2.4.0
  • Method Details

    • getRoutingFunction

      protected org.springframework.web.reactive.function.server.RouterFunction<org.springframework.web.reactive.function.server.ServerResponse> getRoutingFunction(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes)
      Description copied from class: AbstractErrorWebExceptionHandler
      Create a RouterFunction that can route and handle errors as JSON responses or HTML views.

      If the returned RouterFunction doesn't route to a HandlerFunction, the original exception is propagated in the pipeline and can be processed by other WebExceptionHandlers.

      Specified by:
      getRoutingFunction in class AbstractErrorWebExceptionHandler
      Parameters:
      errorAttributes - the ErrorAttributes instance to use to extract error information
      Returns:
      a RouterFunction that routes and handles errors
    • renderErrorView

      protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse> renderErrorView(org.springframework.web.reactive.function.server.ServerRequest request)
      Render the error information as an HTML view.
      Parameters:
      request - the current request
      Returns:
      a Publisher of the HTTP response
    • renderErrorResponse

      protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse> renderErrorResponse(org.springframework.web.reactive.function.server.ServerRequest request)
      Render the error information as a JSON payload.
      Parameters:
      request - the current request
      Returns:
      a Publisher of the HTTP response
    • getErrorAttributeOptions

      protected org.springframework.boot.web.error.ErrorAttributeOptions getErrorAttributeOptions(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.http.MediaType mediaType)
    • isIncludeStackTrace

      protected boolean isIncludeStackTrace(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.http.MediaType produces)
      Determine if the stacktrace attribute should be included.
      Parameters:
      request - the source request
      produces - the media type produced (or MediaType.ALL)
      Returns:
      if the stacktrace attribute should be included
    • isIncludeMessage

      protected boolean isIncludeMessage(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.http.MediaType produces)
      Determine if the message attribute should be included.
      Parameters:
      request - the source request
      produces - the media type produced (or MediaType.ALL)
      Returns:
      if the message attribute should be included
    • isIncludeBindingErrors

      protected boolean isIncludeBindingErrors(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.http.MediaType produces)
      Determine if the errors attribute should be included.
      Parameters:
      request - the source request
      produces - the media type produced (or MediaType.ALL)
      Returns:
      if the errors attribute should be included
    • getHttpStatus

      protected int getHttpStatus(Map<String,Object> errorAttributes)
      Get the HTTP error status information from the error map.
      Parameters:
      errorAttributes - the current error information
      Returns:
      the error HTTP status
    • acceptsTextHtml

      protected org.springframework.web.reactive.function.server.RequestPredicate acceptsTextHtml()
      Predicate that checks whether the current request explicitly support "text/html" media type.

      The "match-all" media type is not considered here.

      Returns:
      the request predicate