Class NtsExceptionTranslator
- java.lang.Object
-
- org.nentangso.core.web.rest.errors.ResponseEntityExceptionHandler
-
- org.nentangso.core.web.rest.errors.NtsExceptionTranslator
-
@ConditionalOnProperty(prefix="nts.web.rest.exception-translator", name="enabled", havingValue="true", matchIfMissing=true) @ControllerAdvice @ConditionalOnMissingBean(name="exceptionTranslator") public class NtsExceptionTranslator extends ResponseEntityExceptionHandlerController advice to translate the server side exceptions to client-friendly json structures. The error response follows RFC7807 - Problem Details for HTTP APIs (RFC7807).
-
-
Field Summary
Fields Modifier and Type Field Description protected StringrealmName-
Fields inherited from class org.nentangso.core.web.rest.errors.ResponseEntityExceptionHandler
logger, PAGE_NOT_FOUND_LOG_CATEGORY, pageNotFoundLogger
-
-
Constructor Summary
Constructors Constructor Description NtsExceptionTranslator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<String,List<String>>buildUnprocessableErrors(Exception ex)protected StringgenerateAuthenticateHeader(Exception ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)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.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>>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>>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>>handleInternalServerError(Exception ex, org.springframework.web.server.ServerWebExchange exchange)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>>handleNtsException(Exception ex, org.springframework.web.server.ServerWebExchange exchange)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.-
Methods inherited from class org.nentangso.core.web.rest.errors.ResponseEntityExceptionHandler
createResponseEntity, handleAsyncRequestTimeoutException, handleException, handleHttpMediaTypeNotAcceptable, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleTypeMismatch
-
-
-
-
Field Detail
-
realmName
@Value("${nts.web.rest.exception-translator.realm-name:API Authentication by nentangso.org}") protected String realmName
-
-
Method Detail
-
handleNtsException
@ExceptionHandler({org.springframework.security.core.AuthenticationException.class,org.springframework.security.access.AccessDeniedException.class,org.springframework.web.server.ResponseStatusException.class,org.springframework.dao.ConcurrencyFailureException.class,org.nentangso.core.service.errors.NotFoundException.class,org.nentangso.core.web.rest.errors.BadRequestAlertException.class,org.nentangso.core.service.errors.FormValidationException.class}) protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleNtsException(Exception ex, org.springframework.web.server.ServerWebExchange exchange)
-
generateAuthenticateHeader
protected String generateAuthenticateHeader(Exception ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.server.ServerWebExchange exchange)
-
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)
Description copied from class:ResponseEntityExceptionHandlerCustomize the response for ConversionNotSupportedException.This method delegates to
ResponseEntityExceptionHandler.handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Overrides:
handleConversionNotSupportedin classResponseEntityExceptionHandler- 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)
Description copied from class:ResponseEntityExceptionHandlerCustomize the response for MissingPathVariableException.This method delegates to
ResponseEntityExceptionHandler.handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Overrides:
handleMissingPathVariablein classResponseEntityExceptionHandler- 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
-
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)
Description copied from class:ResponseEntityExceptionHandlerCustomize the response for HttpRequestMethodNotSupportedException.This method logs a warning, sets the "Allow" header, and delegates to
ResponseEntityExceptionHandler.handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Overrides:
handleHttpRequestMethodNotSupportedin classResponseEntityExceptionHandler- 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)
Description copied from class:ResponseEntityExceptionHandlerCustomize the response for HttpMediaTypeNotSupportedException.This method sets the "Accept" header and delegates to
ResponseEntityExceptionHandler.handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Overrides:
handleHttpMediaTypeNotSupportedin classResponseEntityExceptionHandler- 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)
Description copied from class:ResponseEntityExceptionHandlerCustomize the response for ServletRequestBindingException.This method delegates to
ResponseEntityExceptionHandler.handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Overrides:
handleServletRequestBindingExceptionin classResponseEntityExceptionHandler- 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)
Description copied from class:ResponseEntityExceptionHandlerCustomize the response for MethodArgumentNotValidException.This method delegates to
ResponseEntityExceptionHandler.handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Overrides:
handleMethodArgumentNotValidin classResponseEntityExceptionHandler- 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)
Description copied from class:ResponseEntityExceptionHandlerCustomize the response for MissingServletRequestPartException.This method delegates to
ResponseEntityExceptionHandler.handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Overrides:
handleMissingServletRequestPartin classResponseEntityExceptionHandler- 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
-
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)
Description copied from class:ResponseEntityExceptionHandlerCustomize the response for MissingServletRequestParameterException.This method delegates to
ResponseEntityExceptionHandler.handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Overrides:
handleMissingServletRequestParameterin classResponseEntityExceptionHandler- 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)
Description copied from class:ResponseEntityExceptionHandlerCustomize the response for BindException.This method delegates to
ResponseEntityExceptionHandler.handleExceptionInternal(java.lang.Exception, java.lang.Object, org.springframework.http.HttpHeaders, org.springframework.http.HttpStatus, org.springframework.web.server.ServerWebExchange).- Overrides:
handleBindExceptionin classResponseEntityExceptionHandler- 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)
Description copied from class:ResponseEntityExceptionHandlerA single place to customize the response body of all exception types.- Overrides:
handleExceptionInternalin classResponseEntityExceptionHandler- 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
-
buildUnprocessableErrors
protected Map<String,List<String>> buildUnprocessableErrors(Exception ex)
-
handleInternalServerError
@ExceptionHandler(java.lang.Exception.class) protected reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Object>> handleInternalServerError(Exception ex, org.springframework.web.server.ServerWebExchange exchange)
-
-