public abstract class SphereServiceException extends SphereException
For inspiration how to create exceptions in unit tests:
import io.sphere.sdk.client.*;
import io.sphere.sdk.http.HttpResponse;
import io.sphere.sdk.projects.queries.ProjectGet;
import org.junit.Test;
import java.time.Duration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.catchThrowable;
public class ServerErrorExceptionDemoTest { @Test public void httpCodesAndTheCorrespondingExceptions() { httpCodeExpectedResult(500, InternalServerErrorException.class); httpCodeExpectedResult(502, BadGatewayException.class); httpCodeExpectedResult(503, ServiceUnavailableException.class); httpCodeExpectedResult(504, GatewayTimeoutException.class); } public static BlockingSphereClient clientForStatusCode(final int statusCode) { final SphereClient sphereClient = TestDoubleSphereClientFactory .createHttpTestDouble(intent -> HttpResponse.of(statusCode)); return BlockingSphereClient.of(sphereClient, Duration.ofMillis(100)); } private void httpCodeExpectedResult(final int statusCode, final Class<? extends ServerErrorException> type) { final Throwable throwable = catchThrowable(() -> clientForStatusCode(statusCode).executeBlocking(ProjectGet.of())); assertThat(throwable).isInstanceOf(type); } }
See the test code.
httpResponse
Constructor and Description |
---|
SphereServiceException(Integer statusCode) |
SphereServiceException(String message,
Integer statusCode) |
SphereServiceException(String message,
Throwable cause,
Integer statusCode) |
SphereServiceException(Throwable cause,
Integer statusCode) |
Modifier and Type | Method and Description |
---|---|
com.fasterxml.jackson.databind.JsonNode |
getJsonBody() |
Integer |
getStatusCode() |
addNote, getAdditionalNotes, getHttpResponse, getMessage, getProjectKey, getSphereRequest, httpSummary, setHttpRequest, setProjectKey, setSphereRequest, setUnderlyingHttpResponse
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
public SphereServiceException(Integer statusCode)