Explorar o código

Handle network errors gracefully

Vishnu Mohandas %!s(int64=4) %!d(string=hai) anos
pai
achega
f06b4f1e9f
Modificáronse 1 ficheiros con 11 adicións e 6 borrados
  1. 11 6
      lib/services/sync_service.dart

+ 11 - 6
lib/services/sync_service.dart

@@ -44,7 +44,7 @@ class SyncService {
 
 
   SyncService._privateConstructor() {
   SyncService._privateConstructor() {
     Bus.instance.on<SubscriptionPurchasedEvent>().listen((event) {
     Bus.instance.on<SubscriptionPurchasedEvent>().listen((event) {
-      _uploader.clearQueue(SyncStopRequestedError());
+      _uploader.clearQueue(SilentlyCancelUploadsError());
       sync();
       sync();
     });
     });
 
 
@@ -91,7 +91,7 @@ class SyncService {
     } on WiFiUnavailableError {
     } on WiFiUnavailableError {
       _logger.warning("Not uploading over mobile data");
       _logger.warning("Not uploading over mobile data");
       Bus.instance.fire(
       Bus.instance.fire(
-          SyncStatusUpdate(SyncStatus.paused, reason: "Waiting for WiFi..."));
+          SyncStatusUpdate(SyncStatus.paused, reason: "waiting for WiFi..."));
     } on SyncStopRequestedError {
     } on SyncStopRequestedError {
       _syncStopRequested = false;
       _syncStopRequested = false;
       Bus.instance
       Bus.instance
@@ -103,10 +103,15 @@ class SyncService {
       Bus.instance.fire(SyncStatusUpdate(SyncStatus.error,
       Bus.instance.fire(SyncStatusUpdate(SyncStatus.error,
           error: StorageLimitExceededError()));
           error: StorageLimitExceededError()));
     } catch (e, s) {
     } catch (e, s) {
-      _logger.severe(e, s);
-      Bus.instance
-          .fire(SyncStatusUpdate(SyncStatus.error, reason: "backup failed"));
-      throw e;
+      if (e is DioError && e.error?.osError?.errorCode == 111) {
+        Bus.instance.fire(SyncStatusUpdate(SyncStatus.paused,
+            reason: "waiting for network..."));
+      } else {
+        _logger.severe(e, s);
+        Bus.instance
+            .fire(SyncStatusUpdate(SyncStatus.error, reason: "backup failed"));
+        throw e;
+      }
     } finally {
     } finally {
       if (!successful) {
       if (!successful) {
         _existingSync.completeError(Error());
         _existingSync.completeError(Error());