2015-03-02 151 views
5

如何获取Refit.ApiException的内容?Refit.ApiException错误处理

根据内容是什么,我想让用户知道如何继续。所以我看到抛出的异常有以下内容...

内容“{\”error \“:\”invalid_grant \“,\”error_description \“:\”用户名或密码不正确。\“ }“

问题是,我如何访问它?

+0

通过RestService类https://github.com/paulcbetts/refit/blob/master/Refit/RestService.cs去想通了,我可以用GetContentAs 方法((Refit.ApiException )ex).GetContentAs >() – crazyDiamond 2015-03-03 16:42:00

回答

3

您可以为ApiException添加一个catch块。你可以从这个catch块获取内容。下面 请参阅:

catch (ApiException ex) 
{ 
    var content = ex.GetContentAs<Dictionary<String, String>>(); 
    Debug.WriteLine(ex.Message); 
}