Class ResponseEntityExceptionHandler
- java.lang.Object
-
- org.nentangso.core.web.rest.errors.ResponseEntityExceptionHandler
-
- Direct Known Subclasses:
NtsExceptionTranslator
public abstract class ResponseEntityExceptionHandler extends Object
A class with an@ExceptionHandlermethod that handles all Spring WebFlux raised exceptions by returning aResponseEntitywith RFC 7807 formatted error details in the body.Convenient as a base class of an
@ControllerAdvicefor global exception handling in an application. Subclasses can override individual methods that handle a specific exception, overridehandleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange)to override common handling of all exceptions, orcreateResponseEntity(java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange)to intercept the final step of creating the
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.logging.LogloggerCommon logger for use in subclasses.static StringPAGE_NOT_FOUND_LOG_CATEGORYLog category to use when no mapped handler is found for a request.protected static org.apache.commons.logging.LogpageNotFoundLoggerSpecific logger to use when no mapped handler is found for a request.
-
Constructor Summary
Constructors Constructor Description ResponseEntityExceptionHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>createResponseEntity(Object body, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Create theResponseEntityto use from the given body, headers, and statusCode.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleAsyncRequestTimeoutException(org.springframework.web.context.request.async.AsyncRequestTimeoutException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for AsyncRequestTimeoutException.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleBindException(org.springframework.validation.BindException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for BindException.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleConversionNotSupported(org.springframework.beans.ConversionNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for ConversionNotSupportedException.reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleException(Exception ex, org.springframework.web.server.ServerWebExchange exchange)Provides handling for standard Spring MVC exceptions.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleExceptionInternal(Exception ex, Object body, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)A single place to customize the response body of all exception types.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleHttpMediaTypeNotAcceptable(org.springframework.web.HttpMediaTypeNotAcceptableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for HttpMediaTypeNotAcceptableException.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleHttpMediaTypeNotSupported(org.springframework.web.HttpMediaTypeNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for HttpMediaTypeNotSupportedException.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleHttpMessageNotReadable(org.springframework.http.converter.HttpMessageNotReadableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for HttpMessageNotReadableException.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleHttpMessageNotWritable(org.springframework.http.converter.HttpMessageNotWritableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for HttpMessageNotWritableException.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleHttpRequestMethodNotSupported(org.springframework.web.HttpRequestMethodNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for HttpRequestMethodNotSupportedException.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for MethodArgumentNotValidException.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleMissingPathVariable(org.springframework.web.bind.MissingPathVariableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for MissingPathVariableException.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for MissingServletRequestParameterException.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleMissingServletRequestPart(org.springframework.web.multipart.support.MissingServletRequestPartException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for MissingServletRequestPartException.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for ServletRequestBindingException.protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>>handleTypeMismatch(org.springframework.beans.TypeMismatchException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)Customize the response for TypeMismatchException.
-
-
-
Field Detail
-
PAGE_NOT_FOUND_LOG_CATEGORY
public static final String PAGE_NOT_FOUND_LOG_CATEGORY
Log category to use when no mapped handler is found for a request.- See Also:
pageNotFoundLogger, Constant Field Values
-
pageNotFoundLogger
protected static final org.apache.commons.logging.Log pageNotFoundLogger
Specific logger to use when no mapped handler is found for a request.- See Also:
PAGE_NOT_FOUND_LOG_CATEGORY
-
logger
protected final org.apache.commons.logging.Log logger
Common logger for use in subclasses.
-
-
Method Detail
-
handleException
@ExceptionHandler({org.springframework.web.HttpRequestMethodNotSupportedException.class,org.springframework.web.HttpMediaTypeNotSupportedException.class,org.springframework.web.HttpMediaTypeNotAcceptableException.class,org.springframework.web.bind.MissingPathVariableException.class,org.springframework.web.bind.MissingServletRequestParameterException.class,org.springframework.web.bind.ServletRequestBindingException.class,org.springframework.beans.ConversionNotSupportedException.class,org.springframework.beans.TypeMismatchException.class,org.springframework.http.converter.HttpMessageNotReadableException.class,org.springframework.http.converter.HttpMessageNotWritableException.class,org.springframework.web.bind.MethodArgumentNotValidException.class,org.springframework.web.multipart.support.MissingServletRequestPartException.class,org.springframework.validation.BindException.class,org.springframework.web.context.request.async.AsyncRequestTimeoutException.class}) @Nullable public final reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleException(Exception ex, org.springframework.web.server.ServerWebExchange exchange)Provides handling for standard Spring MVC exceptions.- Parameters:
ex- the target exceptionexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleHttpRequestMethodNotSupported
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleHttpRequestMethodNotSupported(org.springframework.web.HttpRequestMethodNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for HttpRequestMethodNotSupportedException.This method logs a warning, sets the "Allow" header, and delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleHttpMediaTypeNotSupported
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleHttpMediaTypeNotSupported(org.springframework.web.HttpMediaTypeNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for HttpMediaTypeNotSupportedException.This method sets the "Accept" header and delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleHttpMediaTypeNotAcceptable
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleHttpMediaTypeNotAcceptable(org.springframework.web.HttpMediaTypeNotAcceptableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for HttpMediaTypeNotAcceptableException.This method delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleMissingPathVariable
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleMissingPathVariable(org.springframework.web.bind.MissingPathVariableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for MissingPathVariableException.This method delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response - Since:
- 4.2
-
handleMissingServletRequestParameter
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for MissingServletRequestParameterException.This method delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleServletRequestBindingException
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for ServletRequestBindingException.This method delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleConversionNotSupported
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleConversionNotSupported(org.springframework.beans.ConversionNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for ConversionNotSupportedException.This method delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleTypeMismatch
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleTypeMismatch(org.springframework.beans.TypeMismatchException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for TypeMismatchException.This method delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleHttpMessageNotReadable
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleHttpMessageNotReadable(org.springframework.http.converter.HttpMessageNotReadableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for HttpMessageNotReadableException.This method delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleHttpMessageNotWritable
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleHttpMessageNotWritable(org.springframework.http.converter.HttpMessageNotWritableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for HttpMessageNotWritableException.This method delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleMethodArgumentNotValid
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for MethodArgumentNotValidException.This method delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleMissingServletRequestPart
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleMissingServletRequestPart(org.springframework.web.multipart.support.MissingServletRequestPartException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for MissingServletRequestPartException.This method delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleBindException
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleBindException(org.springframework.validation.BindException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for BindException.This method delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleAsyncRequestTimeoutException
@Nullable protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleAsyncRequestTimeoutException(org.springframework.web.context.request.async.AsyncRequestTimeoutException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Customize the response for AsyncRequestTimeoutException.This method delegates to
handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Parameters:
ex- the exceptionheaders- the headers to be written to the responsestatus- the selected response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
handleExceptionInternal
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleExceptionInternal(Exception ex, @Nullable Object body, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
A single place to customize the response body of all exception types.- Parameters:
ex- the exceptionbody- the body for the responseheaders- the headers for the responsestatus- the response statusexchange- the current request and response- Returns:
- a
Monowith theResponseEntityfor the response
-
createResponseEntity
protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> createResponseEntity(@Nullable Object body, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
Create theResponseEntityto use from the given body, headers, and statusCode. Subclasses can override this method to inspect and possibly modify the body, headers, or statusCode, e.g. to re-create an instance of- Parameters:
body- the body to use for the responseheaders- the headers to use for the responsestatus- the status code to use for the responseexchange- the current request and response- Returns:
- a
Monowith the createdResponseEntity
-
-