-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[breaking change] HttpClient
: change StateError
to RedirectException
when redirect response has no Location
header
#53618
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
HttpClient
: change StateError
to RedirectException
when response has no Location
header HttpClient
: change StateError
to RedirectException
when redirect response has no Location
header
Technically not breaking to change a thrown error to something else, but if it's the only signal we've given people, for something which ought to have been an exception, it's likely it's been treated like an exception. |
How is that not breaking? If my current code is: do {
try {
HttpClientRequest request = await client.get('brokenserver.com?token=$token', 80, '/');
} on StateError {
// brokenserver.com serves broken redirects if the auth token has expired, refetch it
token = reauth(...);
continue;
}
break;
} while (true) Then I will break because I'm handling |
@brianquinlan based on @lrhn comment and the context you provided in the following comment, I assume we are still considering this as a breaking change to go through the approval process. Am I misreading this? |
@brianquinlan If some program starts using private API from In this particular case, because we probably should have made it an exception to begin with, and users have had no alternative to handle the exceptional situation other than to catch the error, we will treat it as if it has been an exception. (A less breaking change could be to throw an object which implements both |
@itsjustkevin - based on @lrhn's comment, I'm not sure ;-) It seems safer to follow the process and deciders can just give a quick +1 if they don't consider this change to be breaking ;-) |
Got it @brianquinlan. Thoughts on this @Hixie @vsmenon @grouma? |
How do we intend to surface this problematic code? |
I don't know if there is a way to do that. |
If we want to be non-breaking, while still pushing people towards the exception, we can introduce a chimera-exception: class _RedirectException extends RedirectException implements StateError {
_RedirectException(super.message, super.redirects);
} and throw that. Then document as throwing Then wait and see. Maybe try to remove the Eventually, do the real breaking change. |
We've used this approach before but it seems pretty high effort considering how unlikely this is to break real code. |
no objections from me |
SGTM. |
Pinging @vsmenon for final review. |
lgtm |
Bug:#53618 Change-Id: Ib7ea9503dd58c0d1c233a85d92d4feb0648a9022 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380380 Commit-Queue: Brian Quinlan <[email protected]> Reviewed-by: Lasse Nielsen <[email protected]>
Change Intent
Currently,
HttpClient
throws aStateError
when the server responds with a 302 but there is noLocation
header.Instead,
RedirectException
(a subclass ofHttpException
) should be thrown.See #53158
Justification
StateError
should be thrown in response to programmer errors, not errors external to the application. Also,HttpException
subclasses are thrown in response to other HTTP protocol errors.Some users (e.g.
package:http
) assume thatHttpClient
will only throwSocketException
orHttpException
.Impact
This will break HTTP client code that catches
StateError
but notHttpException
and interacts with HTTP servers that return 302 but don't include aLocation
header. This seems unlikely to happen in practice.Mitigation
It is likely that no actual code will need to be migrated. In the worst case, an exception type in a
on
clause might need to change.Change Timeline
N/A.
Associated CLs
No response
The text was updated successfully, but these errors were encountered: