-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Bug : Problem with response body, not parsing body if response is 202 #3276
Comments
I through modify converter solved this problem. For example,i modify the
I test it and works well,but I don't know other people need it or not? |
I've write test scenario in CallTest.java, but it passed. This commit link is here. I would like you help me to reconstruct your case, so that one can help you to solve this issue. |
@Jiachen-Zhang Thanks for your help. I gone through your code. In your test case you set body empty string. Instead of empty body just try Please do send |
hey @mangeshsambare did you figure this out? just bumped into something similar and i've tried a few different approaches:
unfortunately no luck yet, i'd appreciate some help. |
@BMarton You can return a default value if contentLength Is zero using retrofit2.Converter.Factory, it works for me
|
你好,你的邮件我已经收到,每天会在晚上查看邮件并回复。急事请打电话
|
I know that Retrofit does not allow the Call without any return types, developer should have to add some object in return type like
Above is client application request checking status of data. In this request, client app gets two types of different responses
200 success
with body &202 accepted
without body. Client app have to call this request with an interval of 5 or n seconds whenever in response client app gets202 accepted
response. If other than202
it gets different status code then client app stops this calling this request.So in this case, client app accept return type of
Response<JsonObject>
In202
accepted response there is no body. So it is gives error :Retrofit2 error java.io.EOFException: End of input at line 1 column 1
I changed this
Response<JsonObject>
toResponse<Object>
&Response<String>
, but still gives same above error.So I solved this issue by changing return type of request from
Response<JsonObject>
toResponse<Void>
as it is suggested hereNow above request is working fine for
202
accepted response. But not working when client app gets200
success response & in that response server sends body in it. In Response object app can not gets body because of return typeVoid
.In above request of return type I use
Response
object likeCall<Response>
. I use this object because client app needs to checkHTTP
status code like200
,202
etc. I changed fromCall<Response>
toCall<ResponseBody>
but it does not return status code. OnlyCall<Response>
object returnsHTTP
status code.In same request, how can I handle null/empty body if I get
202
accepted status code & body data if I get200
success status code?I know that, Retrofit does not allow Call without type like
Call<Response<Void>>
orCall<Response<JsonObject>>
and is not able to map empty body, but what if one of developer have above use case? How can it will be solve? I don't know about any standardization of accepting body only if200
& not in202
, is there any standard way to do this?The text was updated successfully, but these errors were encountered: