如何获取Refit.ApiException的内容?Refit.ApiException错误处理
根据内容是什么,我想让用户知道如何继续。所以我看到抛出的异常有以下内容...
内容“{\”error \“:\”invalid_grant \“,\”error_description \“:\”用户名或密码不正确。\“ }“
问题是,我如何访问它?
如何获取Refit.ApiException的内容?Refit.ApiException错误处理
根据内容是什么,我想让用户知道如何继续。所以我看到抛出的异常有以下内容...
内容“{\”error \“:\”invalid_grant \“,\”error_description \“:\”用户名或密码不正确。\“ }“
问题是,我如何访问它?
通过RestService类https://github.com/paulcbetts/refit/blob/master/Refit/RestService.cs
去想通了,我可以用GetContentAs方法
所以才这样做..
((Refit.ApiException)ex).GetContentAs<Dictionary<String, String>>())
解析出键值的内容。
您可以为ApiException添加一个catch块。你可以从这个catch块获取内容。下面 请参阅:
catch (ApiException ex)
{
var content = ex.GetContentAs<Dictionary<String, String>>();
Debug.WriteLine(ex.Message);
}
通过RestService类https://github.com/paulcbetts/refit/blob/master/Refit/RestService.cs去想通了,我可以用GetContentAs方法((Refit.ApiException )ex).GetContentAs >() –
crazyDiamond
2015-03-03 16:42:00