question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pass the OkHttpResponse object in onResponse method

See original GitHub issue

Could you please provide support for, OkHttpResponse object will get passed as parameter in onResponse method of ParsedRequestListener interface? In that case, we can get the status code/headers from OkHttpResponse object and still enjoying the parsed object in onResponse.

For better visualization, my request can be summarized below,

.getAsParsed(new TypeToken<User>() {}, new ParsedRequestListener<User>() {
    @Override
    public void onResponse(Response response, User user) {
        // we can find header like response.headers()
        // we can get user as parsed
    }

    @Override
    public void onError(ANError anError) {
        // handle error
    }
}); 

Thanks in advance!

P.S: Requested the same feature as a comment in another issue. The issue has been closed. So I am creating a separate issue.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
amitshekhariitbhucommented, Sep 15, 2016

@tausiq - version 0.2.0 has been released with the features that you had requested.

AndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAnUserDetail/{userId}")
                .addPathParameter("userId", "1")
                .setTag(this)
                .setPriority(Priority.LOW)
                .setUserAgent("getAnUser")
                .build()
                .getAsOkHttpResponseAndParsed(new TypeToken<User>() {
                }, new OkHttpResponseAndParsedRequestListener<User>() {
                    @Override
                    public void onResponse(Response okHttpResponse, User user) {
                      // do anything with okHttpResponse and user
                    }
                    @Override
                    public void onError(ANError anError) {
                      // handle error
                    }
                });
1reaction
amitshekhariitbhucommented, Sep 14, 2016

@tausiq how about this. I am planning to add like below in all requests, this will be an optional listener.

AndroidNetworking.get(url)
                .build()
                .setResponseListener(new ResponseListener() {
                    @Override
                    public void onReceived(Response response) {
                        // access header here
                    }
                })
                .getAsParsed(new TypeToken<User>() {
                }, new ParsedRequestListener<User>() {
                    @Override
                    public void onResponse(User user) {

                    }

                    @Override
                    public void onError(ANError anError) {

                    }
                });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't figure out what to check for in OkHttp's onResponse ...
This is my example project. What is the proper way to handle the onResponse method? public class MainActivity extends AppCompatActivity { ...
Read more >
okhttp3.Response.body java code examples - Tabnine
Returns a non-null value if this response was passed to Callback#onResponse or returned from Call#execute(). Response bodies must be ResponseBody and may be ......
Read more >
Using OkHttp | CodePath Android Cliffnotes
It passes a Response object that can be used to check the status code, the response body, and any headers that were returned....
Read more >
Recipes - OkHttp
The string() method on response body is convenient and efficient for small documents. But if the response body is large (greater than 1...
Read more >
OkHttp Android Example Tutorial - DigitalOcean
Asynchronous Calling is the recommneded way since it supports native ... that's a part of OkHttp to define the type of data being...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found