浏览代码

try fix dio future error

melon.yin 2 年之前
父节点
当前提交
d86b3311a0
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11 0
      lib/client_base.dart

+ 11 - 0
lib/client_base.dart

@@ -6,6 +6,10 @@ import 'http_pool.dart';
 import 'interceptor.dart';
 import 'request.dart';
 
+// ignore: unused_element
+const _C_DIO_FUTURE_ERR_MSG = "Future already completed";
+const _C_DIO_FUTURE_ERR_KEYWORDS = "browser_adapter";
+
 /// JSON-RPC Client 基类
 class JsonRpcClientBase {
   /// 服务主机地址
@@ -78,6 +82,13 @@ class JsonRpcClientBase {
       return response.data;
     } on dio.DioError catch (e) {
       throw JsonRpcException(message: "Http error", data: e);
+    } on StateError catch (e) {
+      if (e.message == _C_DIO_FUTURE_ERR_MSG) {
+        if (e.stackTrace != null &&
+            e.stackTrace.toString().contains(_C_DIO_FUTURE_ERR_KEYWORDS)) {
+          // don't rethrow
+        }
+      }
     }
   }