I use:
implementation group: 'com.squareup.retrofit2', name: 'retrofit', version: '2.4.0' implementation group: 'com.squareup.retrofit2', name: 'adapter-rxjava2', version: '2.4.0' implementation group: 'com.squareup.retrofit2', name: 'converter-gson', version: '2.4.0' There is an API request that returns Observable<Response<List<String>>> .
If the server returns a valid json, then I get the desired object. If an error occurred during the request, the server returns nothing and I get the error Caused by: java.io.EOFException: End of input at line 1 column 1 path $ .
Is it possible to somehow get null instead of List<String> ?
Those. with a well-formed query, I can return a List<String> , but if the user does not specify any data, then I cannot query the database and return the result. Those. this is not a server error (5xx), it is a client error (4xx).
I want to get the server response code, but due to the fact that "" is not parsed in the List<String> I get java.io.EOFException and cannot find out what kind of client error (4xx) occurred. Because onError is onError when subscribe , and Response<List<String> falls into onNext .
1) I can give an empty array, but what to do with single objects? Yes, and this approach seems to me wrong. If the data could not be generated for a response, then nothing needs to be returned, only the response code in the header.
2) I thought to always take Observable<Response<String>> and to parse already upon receipt (empty string and any other pass). I will get the server response code and, if successful (201 notes), I will parse the String. But again, it seems a very unfortunate decision.