use of com.apollographql.apollo.exception.ApolloNetworkException in project apollo-android by apollographql.
the class ApolloServerInterceptor method interceptAsync.
@Override
public void interceptAsync(@Nonnull final InterceptorRequest request, @Nonnull final ApolloInterceptorChain chain, @Nonnull Executor dispatcher, @Nonnull final CallBack callBack) {
if (disposed)
return;
dispatcher.execute(new Runnable() {
@Override
public void run() {
callBack.onFetch(FetchSourceType.NETWORK);
try {
httpCall = httpCall(request.operation);
} catch (IOException e) {
logger.e(e, "Failed to prepare http call for operation %s", request.operation.name().name());
callBack.onFailure(new ApolloNetworkException("Failed to prepare http call", e));
return;
}
httpCall.enqueue(new Callback() {
@Override
public void onFailure(@Nonnull Call call, @Nonnull IOException e) {
if (disposed)
return;
logger.e(e, "Failed to execute http call for operation %s", request.operation.name().name());
callBack.onFailure(new ApolloNetworkException("Failed to execute http call", e));
}
@Override
public void onResponse(@Nonnull Call call, @Nonnull Response response) throws IOException {
if (disposed)
return;
callBack.onResponse(new ApolloInterceptor.InterceptorResponse(response));
callBack.onCompleted();
}
});
}
});
}
use of com.apollographql.apollo.exception.ApolloNetworkException in project apollo-android by apollographql.
the class ApolloCallbackTest method onNetworkError.
@Test
public void onNetworkError() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(1);
final AtomicBoolean invoked = new AtomicBoolean();
final Handler callbackHandler = mockCallbackHandler(invoked);
final AtomicReference<ApolloException> exceptionRef = new AtomicReference<>();
apolloClient.query(EMPTY_QUERY).enqueue(ApolloCallback.wrap(new ApolloCall.Callback() {
@Override
public void onResponse(@Nonnull Response response) {
countDownLatch.countDown();
}
@Override
public void onFailure(@Nonnull ApolloException e) {
countDownLatch.countDown();
}
@Override
public void onNetworkError(@Nonnull ApolloNetworkException e) {
exceptionRef.set(e);
countDownLatch.countDown();
}
}, callbackHandler));
countDownLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
assertThat(invoked.get()).isTrue();
assertThat(exceptionRef.get()).isInstanceOf(ApolloNetworkException.class);
}
use of com.apollographql.apollo.exception.ApolloNetworkException in project apollo-android by apollographql.
the class ApolloPrefetchCallbackTest method onNetworkError.
@Test
public void onNetworkError() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(1);
final AtomicBoolean invoked = new AtomicBoolean();
final Handler callbackHandler = mockCallbackHandler(invoked);
apolloClient.prefetch(EMPTY_QUERY).enqueue(ApolloPrefetchCallback.wrap(new ApolloPrefetch.Callback() {
@Override
public void onSuccess() {
fail("Expected onNetworkError");
}
@Override
public void onFailure(@Nonnull ApolloException e) {
fail("Expected onNetworkError");
}
@Override
public void onNetworkError(@Nonnull ApolloNetworkException e) {
countDownLatch.countDown();
}
}, callbackHandler));
countDownLatch.await(2, TimeUnit.SECONDS);
assertThat(invoked.get()).isTrue();
}
Aggregations