Skip to content

Commit

Permalink
Update ReachabilityMonitor Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vsanthanam committed Jun 9, 2022
1 parent 360932d commit e3e3e3f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public final class NetworkMonitor {
private func updateDelegate(path: NWPath) {
delegate?.networkMonitor(self, didUpdateNetworkPath: path)
}

// MARK: - Deinit

deinit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand All @@ -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"
}
}

Expand All @@ -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"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit e3e3e3f

Please sign in to comment.