use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ErrorDecoderTest method testQos429_retryAfter_invalid.
@Test
public void testQos429_retryAfter_invalid() {
Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(429).withHeader(HttpHeaders.RETRY_AFTER, "bad");
assertThat(decoder.isError(response)).isTrue();
RuntimeException result = decoder.decode(response);
assertThat(result).isInstanceOfSatisfying(QosException.Throttle.class, exception -> assertThat(exception.getRetryAfter()).isEmpty());
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ErrorDecoderTest method testQos308_noLocation.
@Test
public void testQos308_noLocation() {
Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(308);
assertThat(decoder.isError(response)).isTrue();
RuntimeException result = decoder.decode(response);
assertThat(result).isInstanceOfSatisfying(UnknownRemoteException.class, exception -> assertThat(exception.getStatus()).isEqualTo(308));
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ErrorDecoderTest method extractsRemoteExceptionForAllErrorCodes.
@Test
public void extractsRemoteExceptionForAllErrorCodes() {
for (int code : ImmutableList.of(300, 400, 404, 500)) {
Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(code).contentType("application/json");
assertThat(decoder.isError(response)).isTrue();
RuntimeException result = decoder.decode(response);
assertThat(result).isInstanceOfSatisfying(RemoteException.class, exception -> {
assertThat(exception.getCause()).isNull();
assertThat(exception.getStatus()).isEqualTo(code);
assertThat(exception.getError().errorCode()).isEqualTo(ErrorType.FAILED_PRECONDITION.code().name());
assertThat(exception.getError().errorName()).isEqualTo(ErrorType.FAILED_PRECONDITION.name());
assertThat(exception.getMessage()).isEqualTo("RemoteException: " + ErrorType.FAILED_PRECONDITION.code().name() + " (" + ErrorType.FAILED_PRECONDITION.name() + ") with instance ID " + SERVICE_EXCEPTION.getErrorInstanceId() + ": {key=value}");
assertThat(exception.getLogMessage()).isEqualTo("RemoteException: " + ErrorType.FAILED_PRECONDITION.code().name() + " (" + ErrorType.FAILED_PRECONDITION.name() + ")");
});
}
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ErrorDecoderTest method testQos503.
@Test
public void testQos503() {
Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(503);
assertThat(decoder.isError(response)).isTrue();
RuntimeException result = decoder.decode(response);
assertThat(result).isInstanceOf(QosException.Unavailable.class);
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ErrorDecoderTest method testQos308_invalidLocation.
@Test
public void testQos308_invalidLocation() {
Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(308).withHeader(HttpHeaders.LOCATION, "invalid");
assertThat(decoder.isError(response)).isTrue();
RuntimeException result = decoder.decode(response);
assertThat(result).isInstanceOfSatisfying(UnknownRemoteException.class, exception -> assertThat(exception.getStatus()).isEqualTo(308));
}
Aggregations