use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class TestGeneralEchoServiceTest method testOnExceptionEchoService.
@Test
public void testOnExceptionEchoService() throws Exception {
final EchoService client = getEchoClient(_client, Bootstrap.getOnExceptionEchoURI());
final String msg = "This is a simple echo message";
final FutureCallback<String> callback = new FutureCallback<>();
client.echo(msg, callback);
try {
callback.get();
Assert.fail("Should have thrown an exception");
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof RemoteInvocationException);
}
}
use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class StreamWriter method onError.
/**
* Notifies the writer that a {@link ChannelPipeline} error is encountered. Only the first invocation
* is raised and the subsequent invocations are ignored.
*
* @param throwable error encountered by the channel pipeline.
*/
public void onError(Throwable throwable) {
if (_wh == null) {
_failureBeforeInit = throwable;
} else {
if (!_errorRaised) {
_wh.error(new RemoteInvocationException(throwable));
_errorRaised = true;
}
}
}
use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.
the class RestClientTest method getErrorResponse.
private <T extends RecordTemplate> RestLiResponseException getErrorResponse(GetResponseOption option, ResponseFuture<T> future, TimeoutOption timeoutOption) throws InterruptedException, TimeoutException, RemoteInvocationException {
Response<T> response = null;
T entity;
RestLiResponseException result = null;
Long l = timeoutOption._l;
TimeUnit timeUnit = timeoutOption._timeUnit;
switch(option) {
case GET:
try {
response = l == null ? future.get() : future.get(l, timeUnit);
Assert.fail("Should have thrown");
} catch (ExecutionException e) {
Throwable cause = e.getCause();
Assert.assertTrue(cause instanceof RestException, "Expected RestLiResponseException not " + cause.getClass().getName());
result = (RestLiResponseException) cause;
}
break;
case GET_RESPONSE:
case GET_RESPONSE_EXPLICIT_THROW:
try {
response = l == null ? future.getResponse() : future.getResponse(l, timeUnit);
Assert.fail("Should have thrown");
} catch (RestLiResponseException e) {
result = e;
}
break;
case GET_RESPONSE_EXPLICIT_NO_THROW:
response = l == null ? future.getResponse() : future.getResponse(l, timeUnit);
result = response.getError();
break;
case GET_RESPONSE_ENTITY:
case GET_RESPONSE_ENTITY_EXPLICIT_THROW:
try {
entity = l == null ? future.getResponseEntity() : future.getResponseEntity(l, timeUnit);
Assert.fail("Should have thrown");
} catch (RestLiResponseException e) {
result = e;
}
break;
case GET_RESPONSE_ENTITY_EXPLICIT_NO_THROW:
entity = l == null ? future.getResponseEntity() : future.getResponseEntity(l, timeUnit);
break;
default:
throw new IllegalStateException();
}
return result;
}
use of com.linkedin.r2.RemoteInvocationException 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.r2.RemoteInvocationException 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);
}
Aggregations