Skip to content

Commit b8e0fdf

Browse files
committed
Elaborate how to use error handling options
1 parent d4b6f55 commit b8e0fdf

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

docs/error-handling.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ in favour of giving you the error as a property.
1616
| `ThrowOnDeserializationError` | 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. |
1717
| `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. |
1818

19-
Those properties are available for the `RestClient` instance and will be used for all request made with that instance.
19+
Those properties are available for the `RestClientOptions` and will be used for all request made with the client instance.
20+
21+
For example, you can configure the client to throw an exception if any error occurs when making a request, or when a request returns a non-successful HTTP status code:
22+
23+
```csharp
24+
var options = new RestClientOptions(url) {
25+
ThrowOnAnyError = true
26+
};
27+
var client = new RestClient(options);
28+
var request = new RestRequest("resource/{id}").AddUrlSegment("id", 123);
29+
var response = await client.ExecuteGetAsync<ResponseModel>(request); // will throw if the request fails
30+
```
2031

2132
::: warning
2233
Please be aware that deserialization failures will only work if the serializer throws an exception when deserializing the response.

0 commit comments

Comments
 (0)