Reland "Cast errors to HttpExceptions and add lint to convert to tidy up dynamic calls in core libraries."

`catchError` in http_impl also handles SocketExceptions.

Change-Id: I865bdd6bde4272f6cb657a86a1c78734e4ee331c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263183
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
This commit is contained in:
Kallen Tu 2022-10-21 18:28:23 +00:00 committed by Commit Queue
parent 30c4cb00b8
commit a5ad599cf0
3 changed files with 14 additions and 5 deletions

View file

@ -1,6 +1,5 @@
{
"org-dartlang-sdk:///lib/_http/http_impl.dart": {
"Dynamic access of 'message'.": 3,
"Dynamic access of 'address'.": 1,
"Dynamic access of 'port'.": 1,
"Dynamic invocation of 'listen'.": 1,

View file

@ -438,8 +438,8 @@ class _HttpIncoming extends Stream<Uint8List> {
{Function? onError, void Function()? onDone, bool? cancelOnError}) {
hasSubscriber = true;
return _stream.handleError((error) {
throw HttpException(error.message, uri: uri);
}).listen(onData,
throw HttpException((error as HttpException).message, uri: uri);
}, test: (error) => error is HttpException).listen(onData,
onError: onError, onDone: onDone, cancelOnError: cancelOnError);
}
@ -2060,15 +2060,24 @@ class _HttpClientConnection {
incoming.drain().then((_) {
_subscription!.resume();
}).catchError((dynamic error, StackTrace stackTrace) {
String message;
if (error is HttpException) {
message = error.message;
} else if (error is SocketException) {
message = error.message;
} else {
throw error;
}
_nextResponseCompleter!.completeError(
HttpException(error.message, uri: _currentUri), stackTrace);
HttpException(message, uri: _currentUri), stackTrace);
_nextResponseCompleter = null;
});
}, test: (error) => error is HttpException || error is SocketException);
} else {
_nextResponseCompleter!.complete(incoming);
_nextResponseCompleter = null;
}
}, onError: (dynamic error, StackTrace stackTrace) {
if (error is! HttpException) throw error; // Rethrow.
_nextResponseCompleter?.completeError(
HttpException(error.message, uri: _currentUri), stackTrace);
_nextResponseCompleter = null;

View file

@ -623,6 +623,7 @@ external dynamic _parseJson(String source, reviver(key, value)?);
// Implementation of encoder/stringifier.
// ignore: avoid_dynamic_calls
dynamic _defaultToEncodable(dynamic object) => object.toJson();
/// JSON encoder that traverses an object structure and writes JSON source.