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

Response body empty when HttpException thrown #361

Closed
mandrizzle opened this issue Mar 27, 2017 · 2 comments
Closed

Response body empty when HttpException thrown #361

mandrizzle opened this issue Mar 27, 2017 · 2 comments
Assignees
Milestone

Comments

@mandrizzle
Copy link

Our GraphQL endpoint requires OAuth authentication. When we use the apollo client to hit our endpoint and our endpoint returns a status code of 401, the apollo client throws an HttpException with a okhttp3.Response object. The problem is, before the exception is thrown, the Response is closed. This means when we try to read the body of the Response when we try to handle the exception, it is blank.

This is from ApolloParseInterceptor#parse which is where the premature closure of the response happens:

  Util.closeQuietly(response);
  throw new HttpException(response);

A solution to this could be to not to add a Response to the exception. We can instead create an immutable object, say NetworkResponse that has a responseBody and responseCode that we can add to the exception.

@BenSchwab
Copy link
Contributor

How does following Retrofit's HttpException sound:
https://github.com/square/retrofit/blob/bd8e38d406fff637ed69b1b312a8e439aa28b012/retrofit/src/main/java/retrofit2/HttpException.java

cc @sav007

@mandrizzle
Copy link
Author

Looking at Retrofits usage of HttpException it seems like they don't close the response on error. Also I like the idea of adding a statusCode and message directly to the exception, assuming message is the body of the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants