diff --git a/lib/grpc/grpc_req.dart b/lib/grpc/grpc_req.dart index 6c5691ef6..2a0c6ef79 100644 --- a/lib/grpc/grpc_req.dart +++ b/lib/grpc/grpc_req.dart @@ -162,6 +162,7 @@ class GrpcReq { } } else { try { + int? code; String msg = response.headers.value('Grpc-Status-Details-Bin') ?? ''; if (msg.isNotEmpty) { while (msg.length % 4 != 0) { @@ -170,6 +171,7 @@ class GrpcReq { final msgBytes = base64Decode(msg); try { final grpcMsg = Status.fromBuffer(msgBytes); + code = grpcMsg.details.firstOrNull?.status.code; // UNKNOWN : -400 : msg final errMsg = grpcMsg.details .map((e) => e.status.message) @@ -181,7 +183,7 @@ class GrpcReq { msg = utf8.decode(msgBytes, allowMalformed: true); } } - return Error(msg); + return Error(msg, code: code); } catch (e) { return Error(e.toString()); } diff --git a/lib/http/loading_state.dart b/lib/http/loading_state.dart index e1f4f447f..627b59e6f 100644 --- a/lib/http/loading_state.dart +++ b/lib/http/loading_state.dart @@ -53,8 +53,9 @@ class Success extends LoadingState { } class Error extends LoadingState { + final int? code; final String? errMsg; - const Error(this.errMsg); + const Error(this.errMsg, {this.code}); @override bool operator ==(Object other) { diff --git a/lib/pages/common/reply_controller.dart b/lib/pages/common/reply_controller.dart index 9c2ac48c1..3863c618e 100644 --- a/lib/pages/common/reply_controller.dart +++ b/lib/pages/common/reply_controller.dart @@ -131,8 +131,9 @@ abstract class ReplyController extends CommonListController { int? replyType, }) { if (loadingState.value case Error error) { - if (error.errMsg?.contains('关闭评论区') == true) { - SmartDialog.showToast(error.errMsg!); + final errMsg = error.errMsg; + if (errMsg != null && (error.code == 12061 || error.code == 12002)) { + SmartDialog.showToast(errMsg); return; } }