Package com.commercetools.docs.meta
Class ExceptionDocumentation
java.lang.Object
com.commercetools.docs.meta.ExceptionDocumentation
Table of content
The exception hierarchy documentation.
Exceptions
The SDK makes use of exceptions from the Java JDK, such asIllegalArgumentException
, and provides own exceptions which all inherit from BaseException
.
Problems concerning the ApiHttpClient
throw a ApiHttpException
.
JSON serializing and deserializing problems throw JsonException
.
ApiHttpException
is a base exception for all error responses from Composable Commerce (HTTP status code >= 400
).
ApiClientException
expresses errors which can be recovered by the client side (HTTP status code >= 400 and < 500
).
ApiServerException
is for server errors.
Errors
If a command cannot be performed due to unfulfilled preconditions the API can return one error response with multiple errors (listing of error codes). The SDK will then put aBadRequestException
into a CompletionStage
.
Custom HttpExceptionFactory
In case a response with a status code of 400 or higher are treated as errors and raise exceptions. These exceptions
are created by the DefaultHttpExceptionFactory
. In case you want to override the handling you have to implement
this interface and override the default methods if necessary.
public class HttpExceptionFactoryTest {
static class CustomExceptionFactory implements HttpExceptionFactory {
@Override
public ApiHttpException create(ApiHttpRequest request, ApiHttpResponse<byte[]> response) {
return new ApiHttpException(response.getStatusCode(), request.getSecuredBody(), response.getHeaders(),
"something bad happened", response, request);
}
@Override
public ResponseSerializer getResponseSerializer() {
return ResponseSerializer.of();
}
}
@Test
public void customFactory() {
ProjectApiRoot client = ApiRootBuilder.of()
.defaultClient(ServiceRegion.GCP_EUROPE_WEST1.getApiUrl())
.withHttpExceptionFactory(CustomExceptionFactory::new)
.build("my-project-key");
assertThatExceptionOfType(ApiHttpException.class).isThrownBy(() -> client.get().executeBlocking())
.withMessageStartingWith("detailMessage: something bad happened");
}
}
See the test code.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
ExceptionDocumentation
public ExceptionDocumentation()
-