Refit.ApiException Error Handling

crazyDiamond picture crazyDiamond · Mar 2, 2015 · Viewed 12k times · Source

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?

Answer

Pavan V Parekh picture Pavan V Parekh · Dec 9, 2016

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);
}