I have a very basic retrofit setup like below.
@POST(deleteAll/book)
Observable<Response<Void>> deleteAllBook();
// retrofit.create blah blah blah
bookAPI.deleteAllBook()
.subscribeOn()
.observeOn()
.subscribe(new Subscriber<Response<Void>>() {
... onComplete
... onError
... onNext
})
I just ran into a issue where the onError in a subscriber does not get invoked if the server returns a 500 error response code.
Is it the normal behaviour? Or are there any special handling that needs to be done so that all none 2xx responses invokes the onError of a subscriber?
By declaring a type of Observable<Response<Void>> you're indicating to Retrofit that you want onNext to be called with all HTTP responses and only call onError when the network or serialization fails. If you want non-200 status codes to call onError then you should declare Observable<Void>. If you need the information from Response but want a 5xx status code to error then you can either write a custom CallAdapter for this behavior (which is hard) or just apply a map operation that checks the status code and manually throws an HttpException.
@JakeWharton Thanks for the quick answer. I just have some more questions....
In my code, i have a couple types..
I have done Observable<Boolean> I notice this will call onError for 500 status code.
I have also done Observable<MySimpleJSONModel> and this does not call onError.
Are these all expected? What criteria needs to be met for onError to be invoked? Judging by your reply, network and serialization fail will trigger onError. So does that mean MySimpleJSONModel actually serialized properly given my 500 server error response?
I only have these two factories for the retrofit builder.
builder.addConverterFactory(GsonConverterFactory.create());
builder.addCallAdapterFactory(RxJavaCallAdapterFactory.create());
Deserialization is not attempted on non-200 responses, only responses with
a 200 status code.
On Fri, Feb 17, 2017 at 9:25 AM Liu Zhen notifications@github.com wrote:
@JakeWharton https://github.com/JakeWharton Thanks for the quick
answer. I just have some more questions....In my code, i have a couple types..
I have done Observable
I notice this will call onError for 500
status code.I have also done Observable
and this does not call
onError.Are these all expected? What criteria needs to be met for onError to be
invoked? Judging by your reply, network and serialization fail will trigger
onError. So does that mean MySimpleJSONModel actually serialized properly
given my 500 server error response?I only have these two factories for the retrofit builder.
builder.addConverterFactory(GsonConverterFactory.create()); builder.addCallAdapterFactory(RxJavaCallAdapterFactory.create());—
You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub
https://github.com/square/retrofit/issues/2203#issuecomment-280663137,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEYDUo0Ezp2CugUzXdJI2E3cOzjl1ks5rda3MgaJpZM4MDkrY
.
Most helpful comment
By declaring a type of
Observable<Response<Void>>you're indicating to Retrofit that you wantonNextto be called with all HTTP responses and only callonErrorwhen the network or serialization fails. If you want non-200 status codes to callonErrorthen you should declareObservable<Void>. If you need the information fromResponsebut want a 5xx status code to error then you can either write a customCallAdapterfor this behavior (which is hard) or just apply amapoperation that checks the status code and manually throws anHttpException.