-
Notifications
You must be signed in to change notification settings - Fork 417
[http] Fix incorrect IOClient documentation for non-2xx HTTP responses #1948
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
Open
EchoEllet
wants to merge
2
commits into
dart-lang:master
Choose a base branch
from
EchoEllet:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5
−5
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,16 +68,16 @@ class _IOStreamedResponseV2 extends IOStreamedResponse | |
| /// callers to get more detailed exception information for socket-level | ||
| /// failures, if desired. | ||
| /// | ||
| /// For example: | ||
| /// Example: | ||
| /// ```dart | ||
| /// final client = http.Client(); | ||
| /// final client = IOClient(); | ||
| /// late String data; | ||
| /// try { | ||
| /// data = await client.read(Uri.https('example.com', '')); | ||
| /// } on SocketException catch (e) { | ||
| /// // Exception is transport-related, check `e.osError` for more details. | ||
| /// } on http.ClientException catch (e) { | ||
| /// // Exception is HTTP-related (e.g. the server returned a 404 status code). | ||
| /// // Exception is transport-related. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this always transport-related? How about just remove this line. And then wrap the next two lines to 80 columns and I'll merge! |
||
| /// // If platform-specific socket details are needed, catch `SocketException` | ||
| /// // before `ClientException` (or without `ClientException`) and inspect `osError` for more details. | ||
| /// // If the handler for `SocketException` were removed then all exceptions | ||
| /// // would be caught by this handler. | ||
| /// } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous comment was false but I don't think that the new comment is correct either. I think that the exception could be transport-related but it could also be HTTP-related, for example a failure to parse the response message. Maybe restore the previous
SocketExceptionon-clause and change this to.// Exception is HTTP-related (e.g. the client could not parse the server's response).Maybe there is a better (or other) example.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Some
BaseClientimplementations may throwClientExceptionin the event of a TLS handshake error, whereasIOClient(orHttpClientfromdart:io) throwsTlsException.I propose:
Since both
io.SocketExceptionandio.HttpException(and by extensionio.RedirectException) are mapped toClientExceptionfrom thehttppackage.Makes sense. However, I suggest adding a note indicating remove if not needed, since this is already covered by
http.ClientException. Many developers assume they need to handle both when seeing the code.Places that may throw
ClientExceptioninIOClient:Maybe it should throw a Dart error (e.g.,
StateError) instead ofClientException, since this is typically considered a programming bug?When I sent a PR to flutter/packages, the preferred approach was to use
Errors for programming bugs (e.g., flutter/packages#8079)HttpClientfromdart:iothrowsI assume
HttpExceptionmeans something went wrong at the HTTP protocol level.There is also
RedirectExceptionfromdart:io:Which suggests that an HTTP response was at least received?
I'm not sure if
HttpExceptionindicates that a response was received.In either case, this does not suggest
statusCode >= 300(not a successful response or non-2xx).