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
@@ -318,6 +311,39 @@ in favour of giving you the error as a property.
318
311
319
312
Those properties are available for the `RestClient` instance and will be used for all request made with that instance.
320
313
314
+
::: warning
315
+
Please be aware that deserialization failures will only work if the serializer throws an exception when deserializing the response.
316
+
Many serializers don't throw by default, and just return a `null` result. RestSharp is unable to figure out why `null` is returned, so it won't fail in this case.
317
+
Check the serializer documentation to find out if it can be configured to throw on deserialization error.
318
+
:::
319
+
321
320
There are also slight differences on how different overloads handle exceptions.
322
321
323
322
Asynchronous generic methods `GetAsync<T>`, `PostAsync<T>` and so on, which aren't a part of `RestClient` interface (those methods are extension methods) return `Task<T>`. It means that there's no `RestResponse` to set the response status to error. We decided to throw an exception when such a request fails. It is a trade-off between the API consistency and usability of the library. Usually, you only need the content of `RestResponse` instance to diagnose issues and most of the time the exception would tell you what's wrong.
323
+
324
+
Below you can find how different extensions deal with errors. Note that functions, which don't throw by default, will throw exceptions when `ThrowOnAnyError` is set to `true`.
325
+
326
+
| Function | Throws on errors |
327
+
|:----------------------|:-----------------|
328
+
|`ExecuteAsync`| No |
329
+
|`ExecuteGetAsync`| No |
330
+
|`ExecuteGetAsync<T>`| No |
331
+
|`ExecutePostAsync`| No |
332
+
|`ExecutePutAsync`| No |
333
+
|`ExecuteGetAsync<T>`| No |
334
+
|`ExecutePostAsync<T>`| No |
335
+
|`ExecutePutAsync<T>`| No |
336
+
|`GetAsync`| Yes |
337
+
|`GetAsync<T>`| Yes |
338
+
|`PostAsync`| Yes |
339
+
|`PostAsync<T>`| Yes |
340
+
|`PatchAsync`| Yes |
341
+
|`PatchAsync<T>`| Yes |
342
+
|`DeleteAsync`| Yes |
343
+
|`DeleteAsync<T>`| Yes |
344
+
|`OptionsAsync`| Yes |
345
+
|`OptionsAsync<T>`| Yes |
346
+
|`HeadAsync`| Yes |
347
+
|`HeadAsync<T>`| Yes |
348
+
349
+
In addition, all the functions for JSON requests, like `GetJsonAsync` and `PostJsonAsyn` throw an exception if the HTTP call fails.
0 commit comments