Skip to content

Commit dfea89e

Browse files
committed
Fixes #2290
1 parent 58180e8 commit dfea89e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

docs/docs/advanced/error-handling.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Error handling
22

3-
If there is a network transport error (network is down, failed DNS lookup, etc), or any kind of server error (except 404), `RestResponse.ResponseStatus` will be set to `ResponseStatus.Error`, otherwise it will be `ResponseStatus.Completed`.
3+
If there is a network transport error (network is down, failed DNS lookup, etc.), or any kind of server error (except 404), `RestResponse.ResponseStatus` will be set to `ResponseStatus.Error`, otherwise it will be `ResponseStatus.Completed`.
44

5-
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`.
5+
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`.
66
The `Status` property is an indicator of completion independent of the API error handling.
77

88
Normally, RestSharp doesn't throw an exception if the request fails.
99

10-
However, it is possible to configure RestSharp to throw in different situations, when it normally doesn't throw
11-
in favour of giving you the error as a property.
10+
However, it is possible to configure RestSharp to throw in different situations when it normally doesn't throw
11+
in favor of giving you the error as a property.
1212

1313
| Property | Behavior |
1414
|-------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -18,15 +18,19 @@ in favour of giving you the error as a property.
1818

1919
Those properties are available for the `RestClientOptions` and will be used for all request made with the client instance.
2020

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:
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:
2222

2323
```csharp
2424
var options = new RestClientOptions(url) {
2525
ThrowOnAnyError = true
2626
};
2727
var client = new RestClient(options);
2828
var request = new RestRequest("resource/{id}").AddUrlSegment("id", 123);
29+
2930
// 👇 will throw if the request fails
31+
var deserialized = await client.GetAsync<ResponseModel>(request);
32+
33+
// 👇 will NOT throw if the request fails, inspect the response to find out what happened
3034
var response = await client.ExecuteGetAsync<ResponseModel>(request);
3135
```
3236

@@ -38,7 +42,7 @@ Check the serializer documentation to find out if it can be configured to throw
3842

3943
There are also slight differences on how different overloads handle exceptions.
4044

41-
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.
45+
Asynchronous generic methods `GetAsync<T>`, `PostAsync<T>` and so on, which aren't a part of `RestClient` API (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.
4246

4347
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`.
4448

0 commit comments

Comments
 (0)