public abstract class ServerErrorException extends SphereServiceException
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
Modifier | Constructor and Description |
---|---|
protected |
ServerErrorException(Integer statusCode) |
protected |
ServerErrorException(String message,
Integer statusCode) |
getJsonBody, getStatusCode
addNote, getAdditionalNotes, getHttpResponse, getMessage, getProjectKey, getSphereRequest, httpSummary, setHttpRequest, setProjectKey, setSphereRequest, setUnderlyingHttpResponse
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString