How do I get to the content of Refit.ApiException?
Depending on what the inner content is, I want to let the user know how to proceed. So I see that thrown exception has the following content ...
Content "{\"error\":\"invalid_grant\",\"error_description\":\"The user name or password is incorrect.\"}"
The question is, how do I access that?
You can add one catch block for ApiException. and you can get content from this catch block. See below:
catch (ApiException ex)
{
    var content = ex.GetContentAs<Dictionary<String, String>>();
    Debug.WriteLine(ex.Message);
}
Going through the RestService class https://github.com/paulcbetts/refit/blob/master/Refit/RestService.cs
figured out I could use the GetContentAs method
So just did this..
((Refit.ApiException)ex).GetContentAs<Dictionary<String, String>>()) 
to parse out the key value content.
As an extra heads-up:
GetContentAs<T>(); is now deprecated.
Use GetContentAsAsync<T>(); instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With