Class RestApiExceptionMapperForWeb

java.lang.Object
org.bremersee.exception.RestApiExceptionMapperForWeb
All Implemented Interfaces:
RestApiExceptionMapper

public class RestApiExceptionMapperForWeb extends Object implements RestApiExceptionMapper
The implementation of a rest api exception mapper for spring web.
Author:
Christian Bremer
  • Constructor Details

    • RestApiExceptionMapperForWeb

      public RestApiExceptionMapperForWeb(RestApiExceptionMapperProperties properties, String applicationName)
      Instantiates a new rest api exception mapper.
      Parameters:
      properties - the properties
      applicationName - the application name
  • Method Details

    • detectHttpStatus

      protected org.springframework.http.HttpStatusCode detectHttpStatus(Throwable exception, Object handler)
      Detect http status http status.
      Parameters:
      exception - the exception
      handler - the handler
      Returns:
      the http status
    • fromStatus

      protected Optional<org.springframework.http.HttpStatusCode> fromStatus(Integer status)
      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 throwable
      httpStatusCode - 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 type HandlerMethod.
      Specified by:
      build in interface RestApiExceptionMapper
      Parameters:
      exception - the exception (required)
      requestPath - the requested path (optional)
      handler - the handler (optional)
      Returns:
      the rest api exception
    • findHandlerClass

      protected Optional<Class<?>> findHandlerClass(Object handler)
      Find the handler class.
      Parameters:
      handler - the handler
      Returns:
      the class
    • findHandlerMethod

      protected Optional<Method> findHandlerMethod(Object handler)
      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 exception
      exception - the exception
      handler - the handler
      config - 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 exception
      exception - the exception
      handler - the handler
      config - 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 exception
      exception - the exception
      config - 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 exception
      config - 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 exception
      path - the path
      config - 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 exception
      handler - the handler
      config - 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 exception
      stackTrace - the stack trace
      config - 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 exception
      exception - the exception
      config - 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 source
      config - the config
      Returns:
      the rest api exception