You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The most important difference, however, that async methods that are named after
53
+
HTTP methods return the `Task<T>` instead of `Task<IRestResponse<T>>`. Because it
54
+
means that you won't get an error response if the request fails, those methods
55
+
throw an exception.
56
+
57
+
All `ExecuteAsync` overloads, however, behave in the same way as `Execute` and return
58
+
the `IRestResponse` or `IRestResponse<T>`.
59
+
60
+
See below about how RestSharp handles exceptions.
61
+
52
62
## Note About Error Handling
53
63
64
+
If there is a network transport error (network is down, failed DNS lookup, etc), `RestResponse.ResponseStatus` will be set to `ResponseStatus.Error`, otherwise it will be `ResponseStatus.Completed`.
65
+
66
+
If an API returns a 404, `ResponseStatus` will still be `Completed`. If you need access to the HTTP status code returned you will find it at `RestResponse.StatusCode`.
67
+
The `Status` property is an indicator of completion independent of the API error handling.
68
+
54
69
Normally, RestSharp doesn't throw an exception if the request fails.
55
70
56
71
However, it is possible to configure RestSharp to throw in different situations, when it normally doesn't throw
57
72
in favour of giving you the error as a property.
58
73
59
-
[TODO] - add exception handling
74
+
| Property | Behavior |
75
+
| ------------- |:-------------:|
76
+
| FailOnDeserialization | Changes the default behavior when failed deserialization results in a successful response with an empty `Data` property of the response. Setting this property to `true` will tell RestSharp to consider failed deserialization as an error and set the `ResponseStatus` to `Error` accordingly. |
77
+
| ThrowOnDeserialization | Changes the default behavior when failed deserialization results in empty `Data` property of the response. Setting this property to `true` will tell RestSharp to throw when deserialization fails. |
78
+
| ThrowOnAnyError | Setting this property to `true` changes the default behavior and forces RestSharp to throw if any errors occurs when making a request or during deserialization. |
60
79
61
-
If there is a network transport error (network is down, failed DNS lookup, etc), `RestResponse.ResponseStatus` will be set to `ResponseStatus.Error`, otherwise it will be `ResponseStatus.Completed`.
80
+
There are also slight differences on how different overloads handle exceptions.
62
81
63
-
If an API returns a 404, `ResponseStatus` will still be `Completed`. If you need access to the HTTP status code returned you will find it at `RestResponse.StatusCode`.
64
-
The `Status` property is an indicator of completion independent of the API error handling.
82
+
Asynchronous generic methods `GetAsync<T>`, `PostAsync<T>` and so on, which aren't a part of `IRestClient` interface
83
+
(those methods are extension methods) return `Task<T>`. It means that there's no `IRestResponse` to set the response status to error.
84
+
We decided to throw an exception when such a request fails. It is a trade-off between the API
85
+
consistency and usability of the library. Usually, you only need the content of `RestResponse` instance to diagnose issues
86
+
and most of the time the exception would tell you what's wrong.
0 commit comments