grpc / grpc-dart

The Dart language implementation of gRPC.
https://pub.dev/packages/grpc
Apache License 2.0
860 stars 271 forks source link

How to handling error in grpc stream client? #524

Closed bonetoy closed 3 years ago

bonetoy commented 3 years ago

Client code:

final clientCall = rpcClient.streamFunc(rpcStreamController.stream);
await for (var response in clientCall){
   ...
}

I saw some grpc error in locat like this:

Unhandled Exception: gRPC Error (code: xx, codeName: Internal, message: Ops, details: [], rawResponse: null, trailers: {})

I can't find a suspicious place for me to throw or handle exceptions. 😂

mraleph commented 3 years ago

Does

try {
  final clientCall = rpcClient.streamFunc(rpcStreamController.stream);
  await for (var response in clientCall){
   ...
  }
} catch (e) {
}

not catch it?

bonetoy commented 3 years ago

Does

try {
  final clientCall = rpcClient.streamFunc(rpcStreamController.stream);
  await for (var response in clientCall){
   ...
  }
} catch (e) {
}

not catch it?

yep, not catch it. but this working! Thank you for inspiring me. 😀

Futrue<void> callRpc() async {
  ....
}
....
callRpc().onError((e)=>...);