alroyso 1 year ago
parent
commit
a2ce8312c8
1 changed files with 3 additions and 2 deletions
  1. 3 2
      lib/app/network/dio_client.dart

+ 3 - 2
lib/app/network/dio_client.dart

@@ -105,7 +105,7 @@ class CustomInterceptors extends Interceptor {
   }
   @override
   Future<void> onError(DioError err, ErrorInterceptorHandler handler) async {
-    LogHelper().d("错误类型:==== ${err.type}");
+    LogHelper().d("onError");
     // 检查网络连接状态
     bool isConnectNetWork = await isConnected();
 
@@ -113,7 +113,8 @@ class CustomInterceptors extends Interceptor {
       // 无网络连接,设置友好的错误消息
       err.error = AppException(message: "当前网络不可用,请检查您的网络");
       return handler.next(err);
-    } else if (err.error is SocketException || err.error is DioError) {
+    } else if (err.error is SocketException || err.type == DioErrorType.connectTimeout || err.type == DioErrorType.sendTimeout || err.type == DioErrorType.receiveTimeout) {
+      LogHelper().d("错误类型:==== ${err.type}");
       if (_retryCount < _backupUrls.length) {
         // 有网络连接但请求失败,尝试使用备用地址
         err.requestOptions.baseUrl = _backupUrls[_retryCount];