Skip to content

Commit 4b67422

Browse files
committed
🛜 Improved isNetworkUnavailable logic
1 parent 82bde2b commit 4b67422

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

swift-sdk/Internal/HealthMonitor.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ class HealthMonitor {
9494
let currentDate = dateProvider.currentDate
9595
let apiCallRequest = apiCallRequest.addingCreatedAt(currentDate)
9696
if let urlRequest = apiCallRequest.convertToURLRequest(sentAt: currentDate) {
97+
ITBInfo("Attempting to send failed-to-schedule request directly for path: '\(apiCallRequest.getPath())'")
9798
_ = RequestSender.sendRequest(urlRequest, usingSession: networkSession)
99+
} else {
100+
let endpoint = apiCallRequest.endpoint
101+
let path = apiCallRequest.getPath()
102+
ITBError("Failed to convert to URL request in health monitor - endpoint: '\(endpoint)', path: '\(path)'")
98103
}
99104
onError()
100105
}

swift-sdk/Internal/IterableAPICallTaskProcessor.swift

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,38 @@ struct IterableAPICallTaskProcessor: IterableTaskProcessor {
5151
private let dateProvider: DateProviderProtocol
5252

5353
private static func isNetworkUnavailable(sendRequestError: SendRequestError) -> Bool {
54+
// Check for NSURLError codes that indicate network issues
55+
if let nsError = sendRequestError.originalError as? NSError {
56+
if nsError.domain == NSURLErrorDomain {
57+
let networkErrorCodes: Set<Int> = [
58+
NSURLErrorNotConnectedToInternet, // -1009
59+
NSURLErrorNetworkConnectionLost, // -1005
60+
NSURLErrorTimedOut, // -1001
61+
NSURLErrorCannotConnectToHost, // -1004
62+
NSURLErrorDNSLookupFailed, // -1006
63+
NSURLErrorDataNotAllowed, // -1020 (cellular data disabled)
64+
NSURLErrorInternationalRoamingOff // -1018
65+
]
66+
if networkErrorCodes.contains(nsError.code) {
67+
ITBInfo("Network error detected: code=\(nsError.code), description=\(nsError.localizedDescription)")
68+
return true
69+
}
70+
}
71+
}
72+
73+
// Fallback to string check for other network-related errors
5474
if let originalError = sendRequestError.originalError {
55-
return originalError.localizedDescription.lowercased().contains("offline")
56-
} else {
57-
return false
75+
let description = originalError.localizedDescription.lowercased()
76+
let isNetworkError = description.contains("offline") ||
77+
description.contains("network") ||
78+
description.contains("internet") ||
79+
description.contains("connection")
80+
if isNetworkError {
81+
ITBInfo("Network error detected via description: \(originalError.localizedDescription)")
82+
}
83+
return isNetworkError
5884
}
85+
86+
return false
5987
}
6088
}

0 commit comments

Comments
 (0)