http icon indicating copy to clipboard operation
http copied to clipboard

`Bad state: Stream has already been listened to` when accessing response stream in `RetryClient.when`

Open blaugold opened this issue 1 year ago • 0 comments

Reading stream of response in when function of RetryClient causes Bad state: Stream has already been listened to to be thrown from https://github.com/dart-lang/http/blob/master/pkgs/http/lib/retry.dart#L125.

Possible fix:

try {
  _unawaited(response.stream.listen((_) {}).cancel().catchError((_) {}));
} catch (_) {}

blaugold avatar Jun 05 '24 12:06 blaugold