Class HawaiiResponseEntityExceptionHandler
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.MessageSourceAware
In this implementation, the response enrichers are stored in a map, with the class name as key. This means that any enricher can be stored only once. Also, enrichers are not ordered. Subclasses may implement another mechanism if required. This would mean that the following methods would need to be overwritten:
- Since:
- 2.0.0
-
Field Summary
Fields inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
PAGE_NOT_FOUND_LOG_CATEGORY, pageNotFoundLogger
-
Constructor Summary
ConstructorDescriptionHawaiiResponseEntityExceptionHandler
(ModelConverter<org.springframework.validation.ObjectError, ValidationErrorResource> objectErrorResourceAssembler, ModelConverter<ValidationError, ValidationErrorResource> validationErrorResourceAssembler, ExceptionResponseFactory exceptionResponseFactory) -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Object>
accessDeniedException
(org.springframework.security.access.AccessDeniedException ex, org.springframework.web.context.request.WebRequest request) HandlesAccessDeniedException
instances.protected void
addResponseEnricher
(ErrorResponseEnricher errorResponseEnricher) Registers aErrorResponseEnricher
.void
protected ErrorResponseResource
buildErrorResponseBody
(Throwable throwable, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request) Builds a meaningful response body for the given throwable, HTTP status and request.protected void
Configures the error response enrichers.protected Collection<ErrorResponseEnricher>
Returns a collection of registered response enrichers.org.springframework.http.ResponseEntity<Object>
handleApiException
(ApiException e, org.springframework.web.context.request.WebRequest request) HandlesValidationException
instances.org.springframework.http.ResponseEntity<Object>
handleHttpException
(HttpException e, org.springframework.web.context.request.WebRequest request) HandlesHttpException
instances.protected org.springframework.http.ResponseEntity<Object>
handleMethodArgumentNotValid
(org.springframework.web.bind.MethodArgumentNotValidException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatusCode status, org.springframework.web.context.request.WebRequest request) HandlesMethodArgumentNotValidException
instances.org.springframework.http.ResponseEntity<Object>
handleThrowable
(Throwable t, org.springframework.web.context.request.WebRequest request) HandlesThrowable
instances.org.springframework.http.ResponseEntity<Object>
handleValidationException
(ValidationException e, org.springframework.web.context.request.WebRequest request) HandlesValidationException
instances.protected void
removeResponseEnricher
(Class<? extends ErrorResponseEnricher> className) De-registers aErrorResponseEnricher
based on its class name.protected void
removeResponseEnricher
(ErrorResponseEnricher errorResponseEnricher) De-registers aErrorResponseEnricher
.Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
createProblemDetail, createResponseEntity, handleAsyncRequestTimeoutException, handleBindException, handleConversionNotSupported, handleErrorResponseException, handleException, handleExceptionInternal, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMissingPathVariable, handleMissingServletRequestParameter, handleMissingServletRequestPart, handleNoHandlerFoundException, handleServletRequestBindingException, handleTypeMismatch, setMessageSource
-
Constructor Details
-
HawaiiResponseEntityExceptionHandler
public HawaiiResponseEntityExceptionHandler(ModelConverter<org.springframework.validation.ObjectError, ValidationErrorResource> objectErrorResourceAssembler, ModelConverter<ValidationError, ValidationErrorResource> validationErrorResourceAssembler, ExceptionResponseFactory exceptionResponseFactory)
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
handleHttpException
@ExceptionHandler(HttpException.class) @ResponseBody public org.springframework.http.ResponseEntity<Object> handleHttpException(HttpException e, org.springframework.web.context.request.WebRequest request) HandlesHttpException
instances.Each
HttpException
has an associatedHttpStatus
that is used as the response status.- Parameters:
e
- the exceptionrequest
- the current request- Returns:
- a response entity reflecting the current exception
-
handleMethodArgumentNotValid
protected org.springframework.http.ResponseEntity<Object> handleMethodArgumentNotValid(@NonNull org.springframework.web.bind.MethodArgumentNotValidException ex, @NonNull org.springframework.http.HttpHeaders headers, @NonNull org.springframework.http.HttpStatusCode status, @NonNull org.springframework.web.context.request.WebRequest request) HandlesMethodArgumentNotValidException
instances.The response status is: 400 Bad Request.
- Overrides:
handleMethodArgumentNotValid
in classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
- Parameters:
ex
- the exceptionrequest
- the current request- Returns:
- a response entity reflecting the current exception
-
accessDeniedException
@ExceptionHandler(org.springframework.security.access.AccessDeniedException.class) @ResponseBody public org.springframework.http.ResponseEntity<Object> accessDeniedException(org.springframework.security.access.AccessDeniedException ex, org.springframework.web.context.request.WebRequest request) HandlesAccessDeniedException
instances.The response status is: 403 Forbidden.
- Parameters:
ex
- the exceptionrequest
- the current request- Returns:
- a response entity reflecting the current exception
-
handleValidationException
@ExceptionHandler(ValidationException.class) @ResponseBody public org.springframework.http.ResponseEntity<Object> handleValidationException(ValidationException e, org.springframework.web.context.request.WebRequest request) HandlesValidationException
instances.The response status is: 400 Bad Request.
- Parameters:
e
- the exceptionrequest
- the current request- Returns:
- a response entity reflecting the current exception
-
handleApiException
@ExceptionHandler(ApiException.class) @ResponseBody public org.springframework.http.ResponseEntity<Object> handleApiException(ApiException e, org.springframework.web.context.request.WebRequest request) HandlesValidationException
instances.The response status is: 400 Bad Request.
- Parameters:
e
- the exceptionrequest
- the current request- Returns:
- a response entity reflecting the current exception
-
handleThrowable
@ExceptionHandler(java.lang.Throwable.class) @ResponseBody public org.springframework.http.ResponseEntity<Object> handleThrowable(Throwable t, org.springframework.web.context.request.WebRequest request) HandlesThrowable
instances. This method acts as a fallback handler.- Parameters:
t
- the exceptionrequest
- the current request- Returns:
- a response entity reflecting the current exception
-
buildErrorResponseBody
protected ErrorResponseResource buildErrorResponseBody(Throwable throwable, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request) Builds a meaningful response body for the given throwable, HTTP status and request.This method constructs an
ErrorResponseResource
usingexceptionResponseFactory
and then applies the error response enrichers returned fromgetResponseEnrichers()
to complete the response.- Parameters:
throwable
- the exceptionstatus
- the HTTP statusrequest
- the current request- Returns:
- an error response
-
addResponseEnricher
Registers aErrorResponseEnricher
.- Parameters:
errorResponseEnricher
- the error response enricher
-
removeResponseEnricher
De-registers aErrorResponseEnricher
.- Parameters:
errorResponseEnricher
- the error response enricher
-
removeResponseEnricher
De-registers aErrorResponseEnricher
based on its class name.- Parameters:
className
- the class name of theErrorResponseEnricher
to remove
-
configureResponseEnrichers
protected void configureResponseEnrichers()Configures the error response enrichers.Subclasses may override this method to remove existing or add additional listeners, using
addResponseEnricher(ErrorResponseEnricher)
andremoveResponseEnricher(ErrorResponseEnricher)
.The default implementation adds the following listeners:
-
getResponseEnrichers
Returns a collection of registered response enrichers.- Returns:
- the response enrichers
-