public class WebErrorHandlers extends Object
WebErrorHandler implementations. The factory would query all the
implementations to find an appropriate exception handler to handle a particular exception.
WebErrorHandlers is also responsible for Error Code to Error Message translation
and i18n (RIP SRP!). In order to fulfill this requirement, we need an instance of MessageSource
to translate error codes to error messages.
WebErrorHandler implementation to handle the
exception, we would use the LastResortWebErrorHandler as the default exception handler.
If you don't like its exception handling approach, consider passing a valid non-null
defaultWebErrorHandler to the constructor.WebErrorHandler,
HandledException,
LastResortWebErrorHandler| Constructor and Description |
|---|
WebErrorHandlers(org.springframework.context.MessageSource messageSource,
List<WebErrorHandler> webErrorHandlers,
WebErrorHandler defaultWebErrorHandler,
ExceptionRefiner exceptionRefiner,
ExceptionLogger exceptionLogger)
Deprecated.
Use
builder(MessageSource) instead. |
| Modifier and Type | Method and Description |
|---|---|
static WebErrorHandlersBuilder |
builder(org.springframework.context.MessageSource messageSource)
A nexus to the
WebErrorHandlersBuilder API. |
HttpError |
handle(Throwable originalException,
Object httpRequest,
Locale locale)
Given any
exception, first it would select an appropriate exception handler or
falls back to a default handler and then tries to handle the exception using the chosen
handler. |
@Deprecated public WebErrorHandlers(@NonNull org.springframework.context.MessageSource messageSource, @NonNull List<WebErrorHandler> webErrorHandlers, @Nullable WebErrorHandler defaultWebErrorHandler, @Nullable ExceptionRefiner exceptionRefiner, @Nullable ExceptionLogger exceptionLogger)
builder(MessageSource) instead.webErrorHandlerPostProcessorsmessageSource - The code to message translator.webErrorHandlers - Collection of WebErrorHandler implementations.defaultWebErrorHandler - Fallback web error handler.exceptionRefiner - Possibly can refine exceptions before handling them.exceptionLogger - Logs exceptions.public static WebErrorHandlersBuilder builder(@NonNull org.springframework.context.MessageSource messageSource)
WebErrorHandlersBuilder API.messageSource - The abstraction responsible for converting error codes to messages.WebErrorHandlersBuilder in its initial state.NullPointerException - When the given message source is missing.@NonNull public HttpError handle(@Nullable Throwable originalException, @Nullable Object httpRequest, @Nullable Locale locale)
exception, first it would select an appropriate exception handler or
falls back to a default handler and then tries to handle the exception using the chosen
handler. Then would convert the HandledException to its corresponding HttpError.originalException - The originalException to handle.httpRequest - The current HTTP request.locale - Will be used to target a specific locale while translating the codes to error
messages.HttpError instance containing both error and message combinations and also,
the intended HTTP Status Code.Copyright © 2019. All rights reserved.