Package org.bremersee.exception
Class RestApiExceptionMapperForWeb
java.lang.Object
org.bremersee.exception.RestApiExceptionMapperForWeb
- All Implemented Interfaces:
RestApiExceptionMapper
- Direct Known Subclasses:
RestApiExceptionMapperForWebFlux
The implementation of a rest api exception mapper for spring web.
- Author:
- Christian Bremer
-
Constructor Summary
ConstructorDescriptionRestApiExceptionMapperForWeb
(RestApiExceptionMapperProperties properties, String applicationName) Instantiates a new rest api exception mapper. -
Method Summary
Modifier and TypeMethodDescriptionBuild the exception model from the exception, the requested path and a handler.protected org.springframework.http.HttpStatusCode
detectHttpStatus
(Throwable exception, Object handler) Detect http status http status.findHandlerClass
(Object handler) Find the handler class.findHandlerMethod
(Object handler) Find the handler method.protected Optional<org.springframework.http.HttpStatusCode>
fromStatus
(Integer status) From status optional.protected String
Gets error.protected RestApiException
reconfigureRestApiException
(RestApiException source, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Reconfigure rest api exception rest api exception.protected RestApiException
setApplication
(RestApiException restApiException, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets application.protected RestApiException
setCause
(RestApiException restApiException, Throwable exception, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets cause.protected RestApiException
setClassName
(RestApiException restApiException, Throwable exception, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets class name.protected RestApiException
setErrorCode
(RestApiException restApiException, Throwable exception, Object handler, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets error code.protected RestApiException
setHandler
(RestApiException restApiException, Object handler, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets handler.protected RestApiException
setMessage
(RestApiException restApiException, Throwable exception, Object handler, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets message.protected RestApiException
setPath
(RestApiException restApiException, String path, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets path.protected RestApiException
setStackTrace
(RestApiException restApiException, StackTraceElement[] stackTrace, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets stack trace.
-
Constructor Details
-
RestApiExceptionMapperForWeb
public RestApiExceptionMapperForWeb(RestApiExceptionMapperProperties properties, String applicationName) Instantiates a new rest api exception mapper.- Parameters:
properties
- the propertiesapplicationName
- the application name
-
-
Method Details
-
detectHttpStatus
protected org.springframework.http.HttpStatusCode detectHttpStatus(Throwable exception, Object handler) Detect http status http status.- Parameters:
exception
- the exceptionhandler
- the handler- Returns:
- the http status
-
fromStatus
From status optional.- Parameters:
status
- the status- Returns:
- the optional
-
getError
@Nullable protected String getError(Throwable throwable, org.springframework.http.HttpStatusCode httpStatusCode) Gets error.- Parameters:
throwable
- the throwablehttpStatusCode
- the http status code- Returns:
- the error
-
build
Description copied from interface:RestApiExceptionMapper
Build the exception model from the exception, the requested path and a handler. Typically, the handler is of typeHandlerMethod
.- Specified by:
build
in interfaceRestApiExceptionMapper
- Parameters:
exception
- the exception (required)requestPath
- the requested path (optional)handler
- the handler (optional)- Returns:
- the rest api exception
-
findHandlerClass
Find the handler class.- Parameters:
handler
- the handler- Returns:
- the class
-
findHandlerMethod
Find the handler method.- Parameters:
handler
- the handler- Returns:
- the method
-
setErrorCode
protected RestApiException setErrorCode(RestApiException restApiException, Throwable exception, Object handler, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets error code.- Parameters:
restApiException
- the rest api exceptionexception
- the exceptionhandler
- the handlerconfig
- the config- Returns:
- the error code
-
setMessage
protected RestApiException setMessage(RestApiException restApiException, Throwable exception, Object handler, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets message.- Parameters:
restApiException
- the rest api exceptionexception
- the exceptionhandler
- the handlerconfig
- the config- Returns:
- the message
-
setClassName
protected RestApiException setClassName(RestApiException restApiException, Throwable exception, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets class name.- Parameters:
restApiException
- the rest api exceptionexception
- the exceptionconfig
- the config- Returns:
- the class name
-
setApplication
protected RestApiException setApplication(RestApiException restApiException, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets application.- Parameters:
restApiException
- the rest api exceptionconfig
- the config- Returns:
- the application
-
setPath
protected RestApiException setPath(RestApiException restApiException, String path, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets path.- Parameters:
restApiException
- the rest api exceptionpath
- the pathconfig
- the config- Returns:
- the path
-
setHandler
protected RestApiException setHandler(RestApiException restApiException, Object handler, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets handler.- Parameters:
restApiException
- the rest api exceptionhandler
- the handlerconfig
- the config- Returns:
- the handler
-
setStackTrace
protected RestApiException setStackTrace(RestApiException restApiException, StackTraceElement[] stackTrace, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets stack trace.- Parameters:
restApiException
- the rest api exceptionstackTrace
- the stack traceconfig
- the config- Returns:
- the stack trace
-
setCause
protected RestApiException setCause(RestApiException restApiException, Throwable exception, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets cause.- Parameters:
restApiException
- the rest api exceptionexception
- the exceptionconfig
- the config- Returns:
- the cause
-
reconfigureRestApiException
protected RestApiException reconfigureRestApiException(RestApiException source, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Reconfigure rest api exception rest api exception.- Parameters:
source
- the sourceconfig
- the config- Returns:
- the rest api exception
-