-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Allow treating unsuccessful status code as non-error, avoid setting exception #2311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Deploying restsharp with
|
| Latest commit: |
8a8f153
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://48bb00c7.restsharp.pages.dev |
| Branch Preview URL: | https://error-unsuccessful-status-co.restsharp.pages.dev |
PR Compliance Guide 🔍(Compliance updated until commit 8a8f153)Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label Previous compliance checksCompliance check up to commit f8e891a
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
Test Results 35 files 35 suites 15m 51s ⏱️ Results for commit 8a8f153. ♻️ This comment has been updated with latest results. |
Co-authored-by: qodo-merge-for-open-source[bot] <189517486+qodo-merge-for-open-source[bot]@users.noreply.github.com>
User description
Description
Add an option to not set the response exception if the call went toruhg but status code is unsuccessful.
Fixes #2302
Purpose
This pull request is a:
PR Type
Enhancement
Description
Add
ErrorWhenUnsuccessfulStatusCodeoption to control exception behaviorModify
MaybeException()to accept parameter for conditional error handlingRefactor
FromHttpResponse()to acceptReadOnlyRestClientOptionsinstead of individual parametersAdd test coverage for unsuccessful status code without exception
Diagram Walkthrough
File Walkthrough
RestClientOptions.cs
Add ErrorWhenUnsuccessfulStatusCode configuration optionsrc/RestSharp/Options/RestClientOptions.cs
ErrorWhenUnsuccessfulStatusCodeproperty with default valuetruestatus codes
HttpResponseExtensions.cs
Add parameter to control exception creation behaviorsrc/RestSharp/Extensions/HttpResponseExtensions.cs
MaybeException()method to acceptthrowOnUnsuccessfulStatusCodeparameter
nullwhen parameter isfalseregardless ofstatus code
RestResponse.cs
Refactor to use options object in response creationsrc/RestSharp/Response/RestResponse.cs
FromHttpResponse()method signature to acceptReadOnlyRestClientOptionsinstead of individual parametersencodingandcalculateResponseStatusparameters withoptionsparameter
options.Encodingandoptions.CalculateResponseStatusoptions.ErrorWhenUnsuccessfulStatusCodetoMaybeException()callSystem.TextimportRestClient.Async.cs
Update method calls to use new options parametersrc/RestSharp/RestClient.Async.cs
ExecuteAsync()call toFromHttpResponse()with new signatureOptionsobject instead of individualEncodingandCalculateResponseStatusparametersDownloadStreamAsync()to passOptions.ErrorWhenUnsuccessfulStatusCodetoMaybeException()ReadOnlyRestClientOptions.cs
Remove commented codesrc/RestSharp/Options/ReadOnlyRestClientOptions.cs
RequestFailureTests.cs
Add test coverage for new option behaviortest/RestSharp.Tests.Integrated/RequestFailureTests.cs
code
Does_not_throw_on_unsuccessful_status_code_with_option()to verify exception is not set when option is disabled