I'm using Retrofit and Gson to get data from REST service. It's works perfectly, but only when API not returning error. Normally, API return list of objects (as json), but when error occurring, API return a single error object.
I'm trying to obtain Call<List<Link>>
but when API error occurred I'm getting Gson parse error (Expected BEGIN_OBJECT but was BEGIN_ARRAY
).
I've only one solution: retrieving single string and then in enqueue's onResponse()
try to parse response, but here is a lot of boilerplate code.
Is there any better solution of this problem? How to handle API's errors?