From e3e3e3ff494d8e34345e0030ae3386c51b910432 Mon Sep 17 00:00:00 2001 From: Varun Santhanam Date: Thu, 9 Jun 2022 06:51:07 -0700 Subject: [PATCH] Update ReachabilityMonitor Errors --- .../API/NetworkMonitor/NetworkMonitor.swift | 2 +- .../ReachabilityMonitor+Error.swift | 13 ++++++++++--- .../ReachabilityMonitor/ReachabilityMonitor.swift | 8 ++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Sources/NetworkReachability/API/NetworkMonitor/NetworkMonitor.swift b/Sources/NetworkReachability/API/NetworkMonitor/NetworkMonitor.swift index 0822401c..e5892116 100644 --- a/Sources/NetworkReachability/API/NetworkMonitor/NetworkMonitor.swift +++ b/Sources/NetworkReachability/API/NetworkMonitor/NetworkMonitor.swift @@ -246,7 +246,7 @@ public final class NetworkMonitor { private func updateDelegate(path: NWPath) { delegate?.networkMonitor(self, didUpdateNetworkPath: path) } - + // MARK: - Deinit deinit { diff --git a/Sources/NetworkReachability/API/ReachabilityMonitor/ReachabilityMonitor+Error.swift b/Sources/NetworkReachability/API/ReachabilityMonitor/ReachabilityMonitor+Error.swift index 3aabd5f7..1d374aca 100644 --- a/Sources/NetworkReachability/API/ReachabilityMonitor/ReachabilityMonitor+Error.swift +++ b/Sources/NetworkReachability/API/ReachabilityMonitor/ReachabilityMonitor+Error.swift @@ -40,11 +40,14 @@ public extension ReachabilityMonitor { case failedToStartCallback(Int32) /// An error indicating the rachability observation could not be scheduled - case failedToSetRunLoop(Int32) + case failedToSetDispatchQueue(Int32) /// An error indicating the reachability couldn't be obtained from the system case failedToGetFlags(Int32) + /// An unknown error + case unknown + // MARK: - LocalizedError public var errorDescription: String? { @@ -53,10 +56,12 @@ public extension ReachabilityMonitor { return "Couldn't create system reachability reference" case .failedToStartCallback: return "Couldn't start system observability callback" - case .failedToSetRunLoop: + case .failedToSetDispatchQueue: return "Couldn't schedule system observability callback" case .failedToGetFlags: return "Couldn't get system reachability flags" + case .unknown: + return "Unknown ReachabilityMonitor Failure" } } @@ -66,10 +71,12 @@ public extension ReachabilityMonitor { return "SCError Code \(code)" case let .failedToStartCallback(code): return "SCError Code \(code)" - case let .failedToSetRunLoop(code): + case let .failedToSetDispatchQueue(code): return "SCError Code \(code)" case let .failedToGetFlags(code): return "SCError Code \(code)" + case .unknown: + return "SCError Code Unknown" } } diff --git a/Sources/NetworkReachability/API/ReachabilityMonitor/ReachabilityMonitor.swift b/Sources/NetworkReachability/API/ReachabilityMonitor/ReachabilityMonitor.swift index 27be137a..aae21ed4 100644 --- a/Sources/NetworkReachability/API/ReachabilityMonitor/ReachabilityMonitor.swift +++ b/Sources/NetworkReachability/API/ReachabilityMonitor/ReachabilityMonitor.swift @@ -187,7 +187,11 @@ public final class ReachabilityMonitor { let flags = try flags.get() succeed(with: flags) } catch { - fail(with: error as! Error) + if let error = error as? Error { + fail(with: error) + } else { + fail(with: .unknown) + } } } } @@ -226,7 +230,7 @@ public final class ReachabilityMonitor { if !SCNetworkReachabilitySetCallback(ref, callback, &context) { flags = .failure(.failedToStartCallback(SCError())) } else if !SCNetworkReachabilitySetDispatchQueue(ref, .reachabilityMonitorQueue) { - flags = .failure(.failedToSetRunLoop(SCError())) + flags = .failure(.failedToSetDispatchQueue(SCError())) } else { refreshFlags() }