Package org.bremersee.exception
Class RestApiExceptionMapperImpl
- java.lang.Object
-
- org.bremersee.exception.RestApiExceptionMapperImpl
-
- All Implemented Interfaces:
RestApiExceptionMapper
@Validated public class RestApiExceptionMapperImpl extends Object implements RestApiExceptionMapper
The default implementation of a rest api exception mapper.- Author:
- Christian Bremer
-
-
Constructor Summary
Constructors Constructor Description RestApiExceptionMapperImpl(RestApiExceptionMapperProperties properties, String applicationName)Instantiates a new rest api exception mapper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddStackTraceItems(@NotNull org.bremersee.exception.model.RestApiException restApiException, StackTraceElement[] stackTrace)Add stack trace items.org.bremersee.exception.model.RestApiExceptionbuild(@NotNull Throwable exception, String requestPath, Object handler)Build the exception model from the exception, the requested path and an handler.protected org.bremersee.exception.model.HandlerbuildHandler(Object handler)Build the handler model of the rest ape exception.protected org.bremersee.exception.model.RestApiExceptionbuildRestApiExceptionCause(Throwable cause, @NotNull RestApiExceptionMapperProperties.ExceptionMappingConfig config)Build the cause of a rest api exception.protected StringdetectErrorCode(@NotNull Throwable exception, Object handler, @NotNull RestApiExceptionMapperProperties.ExceptionMappingConfig config)Detect the error code.org.springframework.http.HttpStatusdetectHttpStatus(@NotNull Throwable exception, Object handler)Detects the http status.protected @NotNull StringdetectMessage(@NotNull Throwable exception, Object handler, @NotNull RestApiExceptionMapperProperties.ExceptionMappingConfig config)Detect message exception message.protected Class<?>findHandlerClass(Object handler)Find the handler class.protected MethodfindHandlerMethod(Object handler)Find the handler method.List<String>getApiPaths()Gets the paths this mapper is responsible for.
-
-
-
Constructor Detail
-
RestApiExceptionMapperImpl
public RestApiExceptionMapperImpl(RestApiExceptionMapperProperties properties, String applicationName)
Instantiates a new rest api exception mapper.- Parameters:
properties- the propertiesapplicationName- the application name
-
-
Method Detail
-
getApiPaths
public List<String> getApiPaths()
Description copied from interface:RestApiExceptionMapperGets the paths this mapper is responsible for.- Specified by:
getApiPathsin interfaceRestApiExceptionMapper- Returns:
- the list of paths (typically ant paths)
-
detectHttpStatus
public org.springframework.http.HttpStatus detectHttpStatus(@NotNull @NotNull Throwable exception, @Nullable Object handler)Description copied from interface:RestApiExceptionMapperDetects the http status.- Specified by:
detectHttpStatusin interfaceRestApiExceptionMapper- Parameters:
exception- the exception (required)handler- the handler (optional)- Returns:
- the http status
-
build
public org.bremersee.exception.model.RestApiException build(@NotNull @NotNull Throwable exception, @Nullable String requestPath, @Nullable Object handler)Description copied from interface:RestApiExceptionMapperBuild the exception model from the exception, the requested path and an handler. Typically the handler is of typeHandlerMethod.- Specified by:
buildin interfaceRestApiExceptionMapper- Parameters:
exception- the exception (required)requestPath- the requested path (optional)handler- the handler (optional)- Returns:
- the rest api exception
-
findHandlerClass
@Nullable protected Class<?> findHandlerClass(@Nullable Object handler)
Find the handler class.- Parameters:
handler- the handler- Returns:
- the class
-
findHandlerMethod
@Nullable protected Method findHandlerMethod(Object handler)
Find the handler method.- Parameters:
handler- the handler- Returns:
- the method
-
detectMessage
@NotNull protected @NotNull String detectMessage(@NotNull @NotNull Throwable exception, @Nullable Object handler, @NotNull @NotNull RestApiExceptionMapperProperties.ExceptionMappingConfig config)
Detect message exception message.- Parameters:
exception- the exceptionhandler- the handlerconfig- the config- Returns:
- the exception message
-
detectErrorCode
@Nullable protected String detectErrorCode(@NotNull @NotNull Throwable exception, @Nullable Object handler, @NotNull @NotNull RestApiExceptionMapperProperties.ExceptionMappingConfig config)
Detect the error code.- Parameters:
exception- the exceptionhandler- the handlerconfig- the config- Returns:
- the string
-
buildHandler
@Nullable protected org.bremersee.exception.model.Handler buildHandler(@Nullable Object handler)Build the handler model of the rest ape exception.- Parameters:
handler- the handler- Returns:
- the handler model
-
addStackTraceItems
protected void addStackTraceItems(@NotNull @NotNull org.bremersee.exception.model.RestApiException restApiException, @Nullable StackTraceElement[] stackTrace)Add stack trace items.- Parameters:
restApiException- the rest api exceptionstackTrace- the stack trace
-
buildRestApiExceptionCause
@Nullable protected org.bremersee.exception.model.RestApiException buildRestApiExceptionCause(@Nullable Throwable cause, @NotNull @NotNull RestApiExceptionMapperProperties.ExceptionMappingConfig config)Build the cause of a rest api exception.- Parameters:
cause- the causeconfig- the config- Returns:
- the rest api exception
-
-