我使用RestSharp,我想知道处理响应的最佳方式是什么。有ErrorMessage
,ErrorException
和ResponseStatus
RestResponse
但我怎么检查请求是否成功?在RestSharp中处理响应的最佳方式是什么?
我使用此代码。它看起来好吗?
if (response.ResponseStatus != ResponseStatus.Completed)
{
throw new ApplicationException(response.ErrorMessage);
}
如果REST服务响应非200错误,此代码不会引发异常。按照https://github.com/restsharp/RestSharp/wiki/Getting-Started“如果API返回404,ResponseStatus仍然会被完成。” –