Skip to content

Commit 8ce1cba

Browse files
authored
Merge pull request #103 from mcintyre94/fix-github-poll-network-error
Fix GitHub device flow failing when app returns from background
2 parents 57eafc4 + 7640420 commit 8ce1cba

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Wisp/Services/GitHubDeviceFlowClient.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,15 @@ struct GitHubDeviceFlowClient: Sendable {
8686
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
8787
request.httpBody = "client_id=\(Self.clientID)&device_code=\(deviceCode)&grant_type=urn:ietf:params:oauth:grant-type:device_code".data(using: .utf8)
8888

89-
let (data, response) = try await URLSession.shared.data(for: request)
89+
let data: Data
90+
let response: URLResponse
91+
do {
92+
(data, response) = try await URLSession.shared.data(for: request)
93+
} catch let urlError as URLError where [.networkConnectionLost, .notConnectedToInternet, .timedOut].contains(urlError.code) {
94+
// Transient failure — common when app returns from background. Retry on next interval.
95+
logger.warning("Token poll transient network error: \(urlError.localizedDescription)")
96+
continue
97+
}
9098

9199
guard let httpResponse = response as? HTTPURLResponse,
92100
(200...299).contains(httpResponse.statusCode) else {

0 commit comments

Comments
 (0)