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

400 error throwing FileNotFoundException #154

Closed
nynymike opened this issue Jan 20, 2017 · 2 comments
Closed

400 error throwing FileNotFoundException #154

nynymike opened this issue Jan 20, 2017 · 2 comments
Labels

Comments

@nynymike
Copy link

We recently had a complaint from a client about a 400 response from the token endpoint that was causing AppAuth to throw a FileNotFoundException.

com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:238)  at 
com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)

It looks like it came from this library:
https://android.googlesource.com/platform/external/okhttp/+/781c9c2/okhttp-urlconnection/src/main/java/com/squareup/okhttp/internal/huc/HttpURLConnectionImpl.java

@Override public final InputStream getInputStream() throws IOException {
if (getResponseCode() >= HTTP_BAD_REQUEST) {
      throw new FileNotFoundException(url.toString());
    }

So instead of returning the 400, and other details about the message, it just throws a very confusing FileNotFoundException... which you would think would be a 404 if it really couldn't find a resource.

It makes me wonder about the quality of the underlying HTTP library. Is okhttp really good enough? Wouldn't you want to use at least goodhttp or even greathttp?

@iainmcgin
Copy link
Member

Terrible jokes about the HTTP library aside (:smile:), AppAuth actually uses the HttpURLConnection API provided by the Android OS, which in the context of the device / app is being implemented by okhttp. The semantics of HttpURLConnection are such that any response code >= 400 results in a FileNotFoundException being thrown if you ask for the input stream (rather than error stream) of the connection. See the implementation from okhttp2 (embedded in Android itself) here:

https://android.googlesource.com/platform/external/okhttp/+/781c9c2/okhttp-urlconnection/src/main/java/com/squareup/okhttp/internal/huc/HttpURLConnectionImpl.java#238

It was a bug in AppAuth that we were not checking the status code to determine which stream to use, and was recently fixed in #144. This fix will be included in the 0.5.0 release, which I hope to put out today.

@iainmcgin
Copy link
Member

Closing due to lack of activity.

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

No branches or pull requests

2 participants