From ae8e59fb341ce580f2c7e5efc8d2218131ca4036 Mon Sep 17 00:00:00 2001 From: Jamil Date: Fri, 24 Jan 2025 03:39:36 -0800 Subject: [PATCH] refactor(apple): Downgrade update check transient errors (#7847) These can fail sporadically and we don't need to capture them. However, for users who may be experiencing consistent failures or otherwise wondering why their client isn't able to check for updates, we leave them as `warning`. --- .../Views/UpdateNotification.swift | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/swift/apple/FirezoneKit/Sources/FirezoneKit/Views/UpdateNotification.swift b/swift/apple/FirezoneKit/Sources/FirezoneKit/Views/UpdateNotification.swift index 9d14471f4..843d2ce62 100644 --- a/swift/apple/FirezoneKit/Sources/FirezoneKit/Views/UpdateNotification.swift +++ b/swift/apple/FirezoneKit/Sources/FirezoneKit/Views/UpdateNotification.swift @@ -46,14 +46,30 @@ class UpdateChecker { let task = URLSession.shared.dataTask(with: versionCheckUrl) { [weak self] data, response, error in guard let self = self else { return } - if let error = error { + if let error = error as NSError?, + error.domain == NSURLErrorDomain, + [ + NSURLErrorTimedOut, + NSURLErrorCannotFindHost, + NSURLErrorCannotConnectToHost, + NSURLErrorNetworkConnectionLost, + NSURLErrorDNSLookupFailed, + NSURLErrorNotConnectedToInternet + ].contains(error.code) // Don't capture transient errors + { + Log.warning("\(#function): Update check failed: \(error)") + + return + } else if let error = error { Log.error(error) + return } guard let versionInfo = VersionInfo.from(data: data) else { let attemptedVersion = String(data: data ?? Data(), encoding: .utf8) ?? "" Log.error(UpdateError.invalidVersion(attemptedVersion)) + return } @@ -68,11 +84,10 @@ class UpdateChecker { self.notificationAdapter.showUpdateNotification(version: latestVersion) } - } - task.resume() - } + task.resume() +} static func downloadURL() -> URL { if BundleHelper.isAppStore() {