From 61a0a498bb06259007c8ea7d6f2f605960edb888 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Wed, 23 Oct 2024 11:37:05 +0800 Subject: [PATCH] opt: handle grpc error --- lib/grpc/grpc_repo.dart | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/grpc/grpc_repo.dart b/lib/grpc/grpc_repo.dart index 157a5e32..3ee9dcdf 100644 --- a/lib/grpc/grpc_repo.dart +++ b/lib/grpc/grpc_repo.dart @@ -103,12 +103,24 @@ class GrpcRepo { try { return await request(); } catch (e) { + dynamic defMsg() => {'status': false, 'msg': e.toString()}; if (e is GrpcError) { - if (e.message == '12061') { - return {'status': false, 'msg': 'UP主已关闭评论区'}; // to be comfirm + try { + String msg = utf8.decode( + e.details?.firstOrNull?.getFieldOrNull(2), + allowMalformed: true, + ); + if (msg.isNotEmpty) { + return {'status': false, 'msg': msg}; + } else { + return defMsg(); + } + } catch (e1) { + print(e1.toString()); + return defMsg(); } } - return {'status': false, 'msg': e.toString()}; + return defMsg(); } }