Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug NPE at ApolloServerInterceptor #146

Merged
merged 8 commits into from
Apr 12, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,28 @@ public void interceptAsync(@Nonnull final InterceptorRequest request, @Nonnull f
@Override public void run() {
callBack.onFetch(FetchSourceType.NETWORK);

try {
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();
}
});
if (httpCall != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a silent null check can it run the onFailure callback with ApolloNetworkException("Failed to prepare http call, prepared call was null") and return?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have amended the callback to return the ApolloNetworkException. Please see commit - 4a2cb0b. Appreciate if you could release this on your side if you are agreeable to this change.

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();
}
});
}
}
});
}
Expand Down