How to idiomatically handle HTTP error codes when using RestSharp?

后端 未结 3 976
迷失自我
迷失自我 2020-12-29 06:32

I\'m building an HTTP API client using RestSharp, and I\'ve noticed that when the server returns an HTTP error code (401 Unauthorized, 404 Not Found, 500 Internal Server Err

3条回答
  •  既然无缘
    2020-12-29 06:54

    RestSharp has added boolean property IRestResponse.IsSuccessful which covers your use case. I couldn't find any documentation referring to this property, but here's the line that defines the property's method.

    Interesting to note is that RestSharp considers codes 200-299 to be successful, while CodeCaster considers codes 200-399 to be successful.

提交回复
热议问题