question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add IsSuccessStatusCode & EnsureSuccessStatusCode to ContainerResponse/DatabaseResponse

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
YohanSciubukgiancommented, May 28, 2020

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.

0reactions
j82wcommented, May 27, 2020

The CreateDatabaseIfNotExistsAsync and CreateContainerIfNotExistsAsync methods do use the stream APIs to handle the logic.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found