Comments (5)
Sorry for the long wait on this issue. I spent some time investigating it today. Here are my findings:
- It is possible to extract the status code and headers for a network request that results in
NetworkResponse.UnknownError
, but only if the status code lies outside 200-300 range. - If the status code indicates a successful response (200 <= code < 300), Retrofit tries to parse the response body using a registered response converter. If the response converter throws an exception while parsing the body, Retrofit decides that the call failed and only forwards the original call and the raised exception to the registered call adapter. This means that any information related to headers and status code is lost (see here).
- If the status code indicates an unsuccessful response, Retrofit does not try to parse the body and forwards the response to the registered call adapter. In this case, I can manually parse the body and do the right thing.
- Therefore, it is possible to extract the response headers and status code from failed request, but not always. With this in mind, I will update the
NetworkResponse.UnknownError
class to include nullable fields for headers and status code. These fields will be populated only if they can be extracted from the failed request.
The fields will only be unpopulated in a weird scenario where the server responds with a success code and an invalid response body, so I don't think it could be a major problem.
Expect a new release with these fixes soon. Thank you everyone for reporting it.
from networkresponseadapter.
Makes sense. I'll try to experiment with a design in which UnknownResponse
contains nullable headers and response code. Thanks for the example of your usecase!
from networkresponseadapter.
There's no way for NetworkResponseAdapter to know if the received response was valid or not. That's for your JSON deserialization library to handle.
If you can provide a small example here to illustrate your usecase, I can look into it. Otherwise, this is working as intended.
from networkresponseadapter.
I have the same problem.
As an example, my server sends json error responses that we can parse, but for a 429 Too Many Requests response, AWS sends the error response, and not my server. That error response is not parsable, because the json differs from what our own server sends.
In this case, we get an "UnknownError" with a json parse exception. This doesn't tell us anything about the problem, and I can only show a general message to the user.
If UnknownError would have an optional status code, we can at least know what went wrong and present something useful to the user.
from networkresponseadapter.
I'm in an exact same situation here. Our Rest api throws different Error Json responses differentiated by their status code. I do not want to parse all of the error messages I just need to know the 4xx status code to act accordingly.
from networkresponseadapter.
Related Issues (20)
- Get data frrom Retrofit with обработкой Error and Success HOT 1
- V5.0 HOT 6
- NetworkResponse Error Managing HOT 3
- Success code 204 (no content) returns server error HOT 1
- NetworkResponseAdapterFactory crashes on unhandled response types HOT 1
- ResponseHandler should allow to pass our own converter HOT 5
- moshi exception incorrectly classified as network error HOT 2
- NetworkResponse.UnknownError HOT 2
- How to handle responses with 200 **AND** 204 (No Content) HOT 3
- How To Handle Error Response ? HOT 4
- When expression with Success and Error is not exhaustive HOT 4
- Error when app is builded in release mode HOT 2
- Retrofit mock HOT 2
- How to run this source code in Android Studio??? HOT 8
- Are there any projects that have used this library? (open source) HOT 4
- Binaries not available on Maven Central HOT 4
- 5.0.0 is not backwards compatible HOT 2
- Adding NetworkResponseAdapterFactory to your Retrofit client in Java HOT 3
- Excpetion: Unable to create call adapter when I try to use with Retrofit and Moshi HOT 1
- Application crashing when minifyEnabled is set to true HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from networkresponseadapter.