func AddRequireMinimumProtocol(stack *middleware.Stack, major, minor int) error.func AddNoPayloadDefaultContentTypeRemover(stack *middleware.Stack) (err error).func AddHeaderValue(header string, value string) func(stack *middleware.Stack) error.func AddErrorCloseResponseBodyMiddleware(stack *middleware.Stack) error.func AddContentChecksumMiddleware(stack *middleware.Stack) error.func AddComputeContentLengthMiddleware(stack *middleware.Stack) error.func AddCloseResponseBodyMiddleware(stack *middleware.Stack) error.Needed to round trip API operation calls with an service. Package http provides the HTTP transport client and request/response types SplitHTTPDateTimestampHeaderListValues(vs) SetIsContentTypeDefaultValue(ctx, isDefault) RemoveNoPayloadDefaultContentTypeRemover(stack) In addition, all the functions for JSON requests, like GetJsonAsync and PostJsonAsyn throw an exception if the HTTP call fails.AddErrorCloseResponseBodyMiddleware(stack)ĪddNoPayloadDefaultContentTypeRemover(stack)ĪddRequireMinimumProtocol(stack, major, minor) Note that functions, which don't throw by default, will throw exceptions when ThrowOnAnyError is set to true. 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.īelow you can find how different extensions deal with errors. It is a trade-off between the API consistency and usability of the library. We decided to throw an exception when such a request fails. It means that there's no RestResponse to set the response status to error. There are also slight differences on how different overloads handle exceptions.Īsynchronous generic methods GetAsync, PostAsync and so on, which aren't a part of RestClient interface (those methods are extension methods) return Task. Check the serializer documentation to find out if it can be configured to throw on deserialization error. RestSharp is unable to figure out why null is returned, so it won't fail in this case. Many serializers don't throw by default, and just return a null result. Please be aware that deserialization failures will only work if the serializer throws an exception when deserializing the response. Those properties are available for the RestClientOptions and will be used for all request made with the client instance.įor 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: 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. Setting this property to true will tell RestSharp to throw when deserialization fails. Setting this property to true will tell RestSharp to consider failed deserialization as an error and set the ResponseStatus to Error accordingly.Ĭhanges the default behavior when failed deserialization results in empty Data property of the response. PropertyĬhanges the default behavior when failed deserialization results in a successful response with an empty Data property of the response. However, it is possible to configure RestSharp to throw in different situations, when it normally doesn't throw in favour of giving you the error as a property. Normally, RestSharp doesn't throw an exception if the request fails. The Status property is an indicator of completion independent of the API error handling. If you need access to the HTTP status code returned you will find it at RestResponse.StatusCode. ![]() ![]() ![]() If an API returns a 404, ResponseStatus will still be Completed. 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.
0 Comments
Leave a Reply. |