Package org.bremersee.exception
Class RestApiExceptionMapperForWeb
java.lang.Object
org.bremersee.exception.RestApiExceptionMapperForWeb
- All Implemented Interfaces:
RestApiExceptionMapper
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 TypeMethodDescriptionorg.bremersee.exception.model.RestApiException
Build 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 org.bremersee.exception.model.RestApiException
reconfigureRestApiException
(org.bremersee.exception.model.RestApiException source, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Reconfigure rest api exception rest api exception.protected org.bremersee.exception.model.RestApiException
setApplication
(org.bremersee.exception.model.RestApiException restApiException, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets application.protected org.bremersee.exception.model.RestApiException
setCause
(org.bremersee.exception.model.RestApiException restApiException, Throwable exception, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets cause.protected org.bremersee.exception.model.RestApiException
setClassName
(org.bremersee.exception.model.RestApiException restApiException, Throwable exception, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets class name.protected org.bremersee.exception.model.RestApiException
setErrorCode
(org.bremersee.exception.model.RestApiException restApiException, Throwable exception, Object handler, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets error code.protected org.bremersee.exception.model.RestApiException
setHandler
(org.bremersee.exception.model.RestApiException restApiException, Object handler, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets handler.protected org.bremersee.exception.model.RestApiException
setMessage
(org.bremersee.exception.model.RestApiException restApiException, Throwable exception, Object handler, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets message.protected org.bremersee.exception.model.RestApiException
setPath
(org.bremersee.exception.model.RestApiException restApiException, String path, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets path.protected org.bremersee.exception.model.RestApiException
setStackTrace
(org.bremersee.exception.model.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
public org.bremersee.exception.model.RestApiException build(Throwable exception, String requestPath, Object handler) 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 org.bremersee.exception.model.RestApiException setErrorCode(org.bremersee.exception.model.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 org.bremersee.exception.model.RestApiException setMessage(org.bremersee.exception.model.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 org.bremersee.exception.model.RestApiException setClassName(org.bremersee.exception.model.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 org.bremersee.exception.model.RestApiException setApplication(org.bremersee.exception.model.RestApiException restApiException, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets application.- Parameters:
restApiException
- the rest api exceptionconfig
- the config- Returns:
- the application
-
setPath
protected org.bremersee.exception.model.RestApiException setPath(org.bremersee.exception.model.RestApiException restApiException, String path, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets path.- Parameters:
restApiException
- the rest api exceptionpath
- the pathconfig
- the config- Returns:
- the path
-
setHandler
protected org.bremersee.exception.model.RestApiException setHandler(org.bremersee.exception.model.RestApiException restApiException, Object handler, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets handler.- Parameters:
restApiException
- the rest api exceptionhandler
- the handlerconfig
- the config- Returns:
- the handler
-
setStackTrace
protected org.bremersee.exception.model.RestApiException setStackTrace(org.bremersee.exception.model.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 org.bremersee.exception.model.RestApiException setCause(org.bremersee.exception.model.RestApiException restApiException, Throwable exception, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Sets cause.- Parameters:
restApiException
- the rest api exceptionexception
- the exceptionconfig
- the config- Returns:
- the cause
-
reconfigureRestApiException
protected org.bremersee.exception.model.RestApiException reconfigureRestApiException(org.bremersee.exception.model.RestApiException source, RestApiExceptionMapperProperties.ExceptionMappingConfig config) Reconfigure rest api exception rest api exception.- Parameters:
source
- the sourceconfig
- the config- Returns:
- the rest api exception
-