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

HTTP Message must be set for OkHttp 3.8.0 #44

Closed
christiandeange opened this issue Jun 26, 2017 · 2 comments
Closed

HTTP Message must be set for OkHttp 3.8.0 #44

christiandeange opened this issue Jun 26, 2017 · 2 comments

Comments

@christiandeange
Copy link

OkHttpResponseAdapter needs to set the message field to ensure that it is compatible with OkHttp 3.8.0 and later.

From OkHttp's Changelog:

The response message is now non-null. This is the "Not Found" in the status line "HTTP 404 Not Found". If you are building responses programmatically (with new Response.Builder()) you must now always supply a message. An empty string "" is permitted. This value was never null on responses returned by OkHttp itself, and it was an old mistake to permit application code to omit a message.

Sample stack trace:

java.lang.IllegalStateException: message == null
   at okhttp3.Response$Builder.build(Response.java:431)
   at okreplay.OkHttpResponseAdapter.adapt(OkHttpResponseAdapter.java:20)
   at okreplay.OkReplayInterceptor.intercept(OkReplayInterceptor.java:40)
   at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
   at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain
   ...
@felipecsl
Copy link
Collaborator

Thanks for looking into this and reporting it. It has since been fixed on #40 here

I'll cut a new release this week with this fix!

@AlaaOsta
Copy link

AlaaOsta commented Oct 31, 2018

There is still an issue when calling an error thru the Retrofit2 Response static method, you need to set the message to empty as well

 public static <T> Response<T> error(int code, ResponseBody body) {
    if (code < 400) throw new IllegalArgumentException("code < 400: " + code);
    return error(body, new okhttp3.Response.Builder() //
        .code(code)
        .protocol(Protocol.HTTP_1_1)
        .message("")
        .request(new Request.Builder().url("http://localhost/").build())
        .build());
  }

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

No branches or pull requests

3 participants