Skip to content

How to catch the exception thrown by 'ClientTransportConnection.terminate'? #1380

Description

@lindeer

my code is a little different from the big await loop in example:

final req = transport.makeRequest(
    headers.entries.map((e) => Header.ascii(e.key, e.value)).toList(growable: false),
    endStream: false,
  );
req.sendData(utf8.encode(body), endStream: true);
final incoming = req.incomingMessages.asBroadcastStream();
final dataStream = incoming.whereType<DataStreamMessage>().map((msg) => utf8.decode(msg.bytes));
final headerStream = incoming.whereType<HeadersStreamMessage>().expand((e) => e.headers);
final detecting = await dataStream.take(10).join('');
if (somecondition(detecting)) {
  await transport.terminate();
  return;
}
await for (final str in dataStream) {
}

but an exception is thrown when running 'somecondition' branch:

Unhandled exception:
HTTP/2 error: Connection error: Connection is being forcefully terminated. (errorCode: 0)

I added a try-catch and ,but it was not working:

try {
  await  transport.terminate();
} catch (e) {
}
await transport.terminate().catchError((e, s) {
}

How could I catch it?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions