org.springframework.boot.autoconfigure.web.reactive.error

Class DefaultErrorWebExceptionHandler

  • All Implemented Interfaces:
    InitializingBean, ErrorWebExceptionHandler, 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.php'
    • '/<templates>/error/4xx.<ext>'
    • '/<static>/error/4xx.php'
    • '/<templates>/error/error'
    • '/<static>/error/error.php'

    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
    Author:
    Brian Clozel
    • Constructor Detail

      • DefaultErrorWebExceptionHandler

        public DefaultErrorWebExceptionHandler(ErrorAttributes errorAttributes,
                                               ResourceProperties resourceProperties,
                                               ErrorProperties errorProperties,
                                               ApplicationContext applicationContext)
        Create a new DefaultErrorWebExceptionHandler instance.
        Parameters:
        errorAttributes - the error attributes
        resourceProperties - the resources configuration properties
        errorProperties - the error configuration properties
        applicationContext - the current application context
    • Method Detail

      • renderErrorView

        protected reactor.core.publisher.Mono<ServerResponse> renderErrorView(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<ServerResponse> renderErrorResponse(ServerRequest request)
        Render the error information as a JSON payload.
        Parameters:
        request - the current request
        Returns:
        a Publisher of the HTTP response
      • isIncludeStackTrace

        protected boolean isIncludeStackTrace(ServerRequest request,
                                              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
      • getHttpStatus

        protected HttpStatus 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 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
      • logError

        protected void logError(ServerRequest request,
                                HttpStatus errorStatus)
        Log the original exception if handling it results in a Server Error or a Bad Request (Client Error with 400 status code) one.
        Parameters:
        request - the source request
        errorStatus - the HTTP error status