caiyue1993 / IceCream

Sync Realm Database with CloudKit
MIT License
1.94k stars 245 forks source link

How do you handle Cloudkit errors? #154

Open johnnyperdomo opened 5 years ago

johnnyperdomo commented 5 years ago

I know that icecream already does this. But how can we interact with the error handler to update the UI accordingly. How can we know if syncEngine failed?

johnnyperdomo commented 5 years ago

one solution i found to return a response to the user, whether it be a fail or success can be by using Notification Center.

       case .success, 
             NotificationCenter.default.post(name: Notifications.success.name, 
             object: message, userInfo: userInfo)

    ...
        case .networkUnavailable,
             .networkFailure:

             NotificationCenter.default.post(name: Notifications.networkFailure.name, 
             object: message, userInfo: userInfo)

            return .recoverableError(reason: .network, message: message)

     ...

        case .quotaExceeded:

            NotificationCenter.default.post(name: Notifications.quotaExceeded.name, 
            object: message, userInfo: userInfo)

            return .fail(reason: .quotaExceeded, message: message)

    }

//we would do this for all the (CKOperationResultType, CKOperationFailReason)

This is just an idea... im not sure if this is the best solution

caiyue1993 commented 5 years ago

Hi @johnnyperdomo , for the time being IceCream hasn't thrown out the error info to the outside world. So you can not know if SyncEngine fails or not now. We'll add it in the future release.