I need some help with Refit... I'm building an Xamarin.Android app, and I'm using Refit to make some network calls to some endpoints. Based on the normal functionalitty of Refit, we can make it convert the response to a model or a list of models we want:
[Get("/Racas.aspx")]
Task<List<Raca>> GetRacas([AliasAs("token")] string token);
This works as intended, but, since the API returns a different model other than "Raca" when there is any errors, how can I convert it properly?
This is a basic example, only a Get on the endpoint, that will return me a list of the resource with HTTP 200, OR, if anything goes wrong, the server will return me a model called "Mensagem" rather than "Raca" with HTTP 5xx, or 4xx...
How can I proceed with it? The GetRacas() should be able to convert to, based on HTTP code:
Task<List<Raca>> GetRacas()
and
Task<Mensagem> GetRacas()
I'm calling the Tasks of refit like this:
await GetApiService().GetRacas(currentUser.Token).ContinueWith(data =>
{
if (data.IsCompleted && data.Status == TaskStatus.RanToCompletion)
{
...
}
...
});
I appreciate any help! Thanks