Add IsSuccessStatusCode & EnsureSuccessStatusCode to ContainerResponse/DatabaseResponse
See original GitHub issueIs your feature request related to a problem? Please describe. We need to implement our own method to check if the StatusCode is valid or to raise an Exception when required.
Describe the solution you’d like Provide the same implementation as ResponseMessage which provides access to :
public virtual bool IsSuccessStatusCode { get; }
public virtual ResponseMessage EnsureSuccessStatusCode();
Describe alternatives you’ve considered I create my own methods to manage these behaviors because the following methods are not public :
internal static bool IsSuccess(this HttpStatusCode httpStatusCode)
{
return ((int)httpStatusCode >= 200) && ((int)httpStatusCode <= 299);
}
throw new CosmosException(
response.ErrorMessage,
response.StatusCode,
(int)response.StatusCode,
response.Headers.ActivityId,
response.Headers.RequestCharge);
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
c# - Correct use of EnsureSuccessStatusCode and ...
I'm calling my Web API using an HttpClient and I see that there is an EnsureSuccessStatusCode method and an IsSuccessStatusCode property. Which ...
Read more >HttpResponseMessage.EnsureSuccessStatusCode Method
The EnsureSuccessStatusCode method throws an exception if the HTTP response was unsuccessful. In .NET Framework and .NET Core 2.2 and earlier versions, ...
Read more >HttpResponseMessage.EnsureSuccessStatusCode Method
Throws an exception if the HttpResponseMessage.IsSuccessStatusCode property for the HTTP response object is false ; if it's true , then no exception is...
Read more >EnsureSuccessStatusCode should write the response ...
EnsureSuccessStatusCode should write the response content in the exception if set We often face issues when using the method ...
Read more >EnsureSuccessStatusCode as an assertion - ploeh blog
What happens when an assertion against IsSuccessStatusCode fails? Assert.True() Failure Expected: True Actual: False. That's not helpful.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks you for all those details. I have checked the source code & I now have a better understanding on how you are handling all these cases.
The CreateDatabaseIfNotExistsAsync and CreateContainerIfNotExistsAsync methods do use the stream APIs to handle the logic.