如何获取Refit.ApiException的内容?
根据内容的内容,我想让用户知道如何继续。所以我看到抛出的异常有以下内容......
内容“{\”error \“:\”invalid_grant \“,\”error_description \“:\”用户名或密码不正确。\“}”
问题是,我该如何访问?
答案 0 :(得分:7)
浏览RestService类https://github.com/paulcbetts/refit/blob/master/Refit/RestService.cs
想通了我可以使用GetContentAs方法
所以就这样做了..
((Refit.ApiException)ex).GetContentAs<Dictionary<String, String>>())
解析键值内容。
答案 1 :(得分:5)
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);
}
答案 2 :(得分:2)
作为额外的提示:
GetContentAs<T>();
现在已弃用。
改为使用GetContentAsAsync<T>();
。