Refit.ApiException Error Handling

How do I get to the contents of Refit.ApiException?

Depending on the internal content, I want the user to know how to proceed. So I see that the exception for the exception has the following content ...

The contents of "{\" error \ ": \" invalid_grant \ ", \" error_description \ ": \" The username or password is incorrect. \ "}"

The question is, how do I access this?

+5
source share
2 answers

Going through the RestService class https://github.com/paulcbetts/refit/blob/master/Refit/RestService.cs

realized that I could use the GetContentAs method

So simple did it.

((Refit.ApiException)ex).GetContentAs<Dictionary<String, String>>()) 

to analyze the contents of a key value.

+5
source

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); } 
+3
source

Source: https://habr.com/ru/post/1214502/


All Articles