@@ -6,6 +6,7 @@ import 'dart:io';
66
77import 'base_client.dart' ;
88import 'base_request.dart' ;
9+ import 'client.dart' ;
910import 'exception.dart' ;
1011import 'io_streamed_response.dart' ;
1112
@@ -28,9 +29,9 @@ BaseClient createClient() {
2829class _ClientSocketException extends ClientException
2930 implements SocketException {
3031 final SocketException cause;
31- _ClientSocketException (SocketException e, Uri url )
32+ _ClientSocketException (SocketException e, Uri uri )
3233 : cause = e,
33- super (e.message, url );
34+ super (e.message, uri );
3435
3536 @override
3637 InternetAddress ? get address => cause.address;
@@ -40,9 +41,33 @@ class _ClientSocketException extends ClientException
4041
4142 @override
4243 int ? get port => cause.port;
44+
45+ @override
46+ String toString () => 'ClientException with $cause , uri=$uri ' ;
4347}
4448
45- /// A `dart:io` -based HTTP client.
49+ /// A `dart:io` -based HTTP [Client] .
50+ ///
51+ /// If there is a socket-level failure when communicating with the server
52+ /// (for example, if the server could not be reached), [IOClient] will emit a
53+ /// [ClientException] that also implements [SocketException] . This allows
54+ /// callers to get more detailed exception information for socket-level
55+ /// failures, if desired.
56+ ///
57+ /// For example:
58+ /// ```dart
59+ /// final client = http.Client();
60+ /// late String data;
61+ /// try {
62+ /// data = await client.read(Uri.https('example.com', ''));
63+ /// } on SocketException catch (e) {
64+ /// // Exception is transport-related, check `e.osError` for more details.
65+ /// } on http.ClientException catch (e) {
66+ /// // Exception is HTTP-related (e.g. the server returned a 404 status code).
67+ /// // If the handler for `SocketException` were removed then all exceptions
68+ /// // would be caught by this handler.
69+ /// }
70+ /// ```
4671class IOClient extends BaseClient {
4772 /// The underlying `dart:io` HTTP client.
4873 HttpClient ? _inner;
0 commit comments