use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestMockFailedResponseFutureBuilder method testBuildWithErrorResponseTreatServerErrorAsSuccess.
@Test
public void testBuildWithErrorResponseTreatServerErrorAsSuccess() {
ResponseFuture<Greeting> future = buildWithErrorResponse(ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS);
try {
Response<Greeting> response = future.getResponse();
Assert.assertNull(response.getEntity());
Assert.assertEquals(response.getStatus(), 404);
RestLiResponseException restLiResponseException = response.getError();
Assert.assertEquals(restLiResponseException.getStatus(), 404);
Assert.assertEquals(restLiResponseException.getServiceErrorMessage(), "foo");
} catch (Exception e) {
Assert.fail("No exception should have been thrown!");
}
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestMockRestliResponseExceptionBuilder method testBuildDefaults.
@Test
public void testBuildDefaults() {
RestLiResponseException exception = new MockRestliResponseExceptionBuilder().build();
RestResponse errorResponse = exception.getResponse();
assertEquals(exception.getStatus(), 500);
assertEquals(errorResponse.getHeader(RestConstants.HEADER_RESTLI_ERROR_RESPONSE), "true");
assertEquals(errorResponse.getHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION), AllProtocolVersions.LATEST_PROTOCOL_VERSION.toString());
assertTrue(errorResponse.getCookies().isEmpty());
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class ExceptionUtil method exceptionForThrowable.
public static RemoteInvocationException exceptionForThrowable(Throwable e, RestResponseDecoder<?> responseDecoder) {
if (e instanceof RestException) {
final RestException re = (RestException) e;
final RestResponse response = re.getResponse();
final ErrorResponse errorResponse;
// decode the response body when HEADER_RESTLI_ERROR_RESPONSE header is set.
try {
errorResponse = getErrorResponse(response);
} catch (RestLiDecodingException decodingException) {
return new RemoteInvocationException(e.getMessage(), decodingException);
}
Response<?> decodedResponse = null;
final String header = HeaderUtil.getErrorResponseHeaderValue(response.getHeaders());
if (header == null) {
// This is purely to handle case #2 commented above.
try {
decodedResponse = responseDecoder.decodeResponse(response);
} catch (RestLiDecodingException decodingException) {
return new RemoteInvocationException(e.getMessage(), e);
}
}
return new RestLiResponseException(response, decodedResponse, errorResponse, e);
}
if (e instanceof RemoteInvocationException) {
return (RemoteInvocationException) e;
}
return new RemoteInvocationException(e);
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class ExceptionUtil method wrapThrowable.
static RemoteInvocationException wrapThrowable(Throwable e) {
if (e instanceof RestLiResponseException) {
final RestLiResponseException restliException = (RestLiResponseException) e;
final ErrorResponse errorResponse;
try {
errorResponse = getErrorResponse(restliException.getResponse());
} catch (RestLiDecodingException decodingException) {
return new RemoteInvocationException(decodingException);
}
return new RestLiResponseException(restliException.getResponse(), restliException.getDecodedResponse(), errorResponse, restliException);
}
return new RemoteInvocationException(e);
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testDeleteFailure.
@Test
public void testDeleteFailure() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<Void> result = greetings.delete(-1L);
CompletableFuture<Void> future = result.toCompletableFuture();
try {
future.get(5000, TimeUnit.MILLISECONDS);
Assert.fail("Expected failure");
} catch (ExecutionException e) {
Assert.assertEquals(((RestLiResponseException) e.getCause()).getStatus(), 404);
}
}
Aggregations