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>>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>>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>>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>>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.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.validation.BindException.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
-
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
-
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
-
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
-
-