3

I'm calling an endpoint to GET a list of objects from the server. Using Retrofit2.0 + RxJava for the api calls.

The server has made it in such a way that when there are no items in the list, instead of returning an empty list, it returns null with the response code 204...

If I use an Observable<List<Item>> when the list is empty it will hit onError because of the null body If I use Completableor Observable<Void> I won't be able to handle any data returned....

I thought about handling this by verifying the error message and assuming that if is an null exception to continue with the normal flow but I'm not fully comfortable with this hack....

Is there a way to handle this situation?

petrrr33
  • 583
  • 9
  • 24
  • 2
    Maybe this might help: https://stackoverflow.com/questions/43702427/rxjava-and-retrofit-to-handle-empty-data-response – theAsker Feb 18 '19 at 13:22

1 Answers1

0
  • 204 : No content means that the query successfully processed but no information to return.

You can use this in OnError method to have more visibilty :

@Override
public void onError(Throwable e) {
    try {

          Log.e("errorL", ((HttpException) e).response().errorBody().string());

        } catch (IOException e1) {
        e1.printStackTrace();}}

Good luck !

RaffMag
  • 114
  • 5