-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Deprecate or analyzer-warn HttpClient IsSuccessStatusCode and EnsureSuccessStatusCode #113177
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
Comments
Tagging subscribers to this area: @dotnet/ncl |
These are on I don't quite agree that I could see an argument for Having said all that, the proper "recommendation" should be "use |
I literally can not remember a time I've seen someone use these in a way that was correct. They are an anti-pattern. |
I see these as simple helpers that are often useful for ruling out responses that you know definitely aren't okay. They don't prevent you from doing further validation. Helper functions like |
Filed somewhat out of annoyance; I had just fixed a bug hidden by use of this, when an API started returning OK instead of Created. This isn't the first time I've made code more robust by removing use of this API -- I'd agree those other shortcuts are bad for the same reason. I understand it's liked because it's simple, and that'll make it hard to want to do anything about it. But that's part of why I consider them so bad. These are so tempting to use, but are usually a bad choice. |
The team consensus here is that we don't see a need to obsolete these helpers as they don't prevent the user from doing stricter validation, and are often sufficient. But we do see value in improving our documentation to:
|
This is also something where
|
HttpResponseMessage.IsSuccessStatusCode
andHttpResponseMessage.EnsureSuccessStatusCode
are anti-patterns:These encourage non-defensive design: if an API returns 200 OK every day, and one day returns 202 Accepted -- is my app doing the correct thing by assuming both are an equivalent result?
I see these used fairly often, and it's usually the first thing newbies reach for.
.NET should warn people away from these and encourage testing for explicit status codes.
The text was updated successfully, but these errors were encountered: