public class ErrorResponseBuilder extends Object
Throwable
s to ResponseWithErrorCode
s.Modifier and Type | Field and Description |
---|---|
static int |
MAX_STACK_TRACE_LEVEL
The maximum stack trace level to recurse into during error response building.
|
protected IdentityHashMap<Class<?>,ResponseMapper<?>> |
responseMappers |
Constructor and Description |
---|
ErrorResponseBuilder() |
Modifier and Type | Method and Description |
---|---|
ResponseWithErrorCode |
build(Throwable throwable) |
protected int |
getMaxStackTraceLevel() |
<ThrowableT extends Throwable & WithErrorResponse> |
logAsError(Class<ThrowableT> throwableClass)
Defines the use of log level "error" for the given type of Throwable.
|
<ThrowableT extends Throwable & WithErrorResponse> |
logAsInfo(Class<ThrowableT> throwableClass)
Defines the use of log level "info" for the given type of Throwable.
|
<ThrowableT extends Throwable & WithErrorResponse> |
logAsLevel(Class<ThrowableT> throwableClass,
LogLevel logLevel)
Defines the log level to use for the given type of Throwable.
|
<ThrowableT extends Throwable & WithErrorResponse> |
logAsWarning(Class<ThrowableT> throwableClass)
Defines the use of log level "warning" for the given type of Throwable.
|
static ErrorResponseBuilder |
newBuilder()
Creates a new default error response builder.
|
<ThrowableT extends Throwable> |
removeMapping(Class<ThrowableT> throwableClass)
Removes the mapping for a given type of Throwable.
|
protected ResponseWithErrorCode |
toResponse(Throwable throwable) |
protected ResponseWithErrorCode |
toResponse(Throwable throwable,
int stackTraceLevel) |
ErrorResponseBuilder |
withMapper(ResponseMapper<?> responseMapper)
Use the given
ResponseMapper for building the error response. |
<ThrowableT extends Throwable & WithErrorResponse> |
withMapper(ResponseMapper<ThrowableT> responseMapper,
LogLevel logLevel)
Use the given
ResponseMapper for building the error response. |
public static final int MAX_STACK_TRACE_LEVEL
protected final IdentityHashMap<Class<?>,ResponseMapper<?>> responseMappers
@Nonnull public static ErrorResponseBuilder newBuilder()
@Nonnull public ErrorResponseBuilder withMapper(@Nonnull ResponseMapper<?> responseMapper)
ResponseMapper
for building the error response.responseMapper
- The response mapper to use.@Nonnull public <ThrowableT extends Throwable & WithErrorResponse> ErrorResponseBuilder withMapper(@Nonnull ResponseMapper<ThrowableT> responseMapper, @Nonnull LogLevel logLevel)
ResponseMapper
for building the error response.responseMapper
- The response mapper to use.logLevel
- The log level to use with the given response mapper.@Nonnull public <ThrowableT extends Throwable & WithErrorResponse> ErrorResponseBuilder logAsLevel(@Nonnull Class<ThrowableT> throwableClass, @Nonnull LogLevel logLevel)
throwableClass
- The Throwable class.logLevel
- The log level to use.public <ThrowableT extends Throwable & WithErrorResponse> ErrorResponseBuilder logAsError(Class<ThrowableT> throwableClass)
throwableClass
- The Throwable class.public <ThrowableT extends Throwable & WithErrorResponse> ErrorResponseBuilder logAsWarning(Class<ThrowableT> throwableClass)
throwableClass
- The Throwable class.public <ThrowableT extends Throwable & WithErrorResponse> ErrorResponseBuilder logAsInfo(Class<ThrowableT> throwableClass)
throwableClass
- The Throwable class.public <ThrowableT extends Throwable> ErrorResponseBuilder removeMapping(@Nonnull Class<ThrowableT> throwableClass)
throwableClass
- The Throwable class.public ResponseWithErrorCode build(@Nonnull Throwable throwable)
protected int getMaxStackTraceLevel()
protected ResponseWithErrorCode toResponse(@Nonnull Throwable throwable, int stackTraceLevel)
protected ResponseWithErrorCode toResponse(@Nonnull Throwable throwable)
Copyright © 2019 SAP SE. All rights reserved.