Skip to content

Commit

Permalink
dont sync client if client call failed, add retry
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepitre committed Jul 6, 2024
1 parent 7f383e5 commit 860b3a5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Sources/API/ClerkAPIClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ final class ClerkAPIClientDelegate: APIClientDelegate, Sendable {
}

func client(_ client: APIClient, shouldRetry task: URLSessionTask, error: any Error, attempts: Int) async throws -> Bool {

if attempts == 1 {
// try to get the client in sync with the server on errors
try? await Clerk.shared.getOrCreateClient()
if let lastPathComponent = task.originalRequest?.url?.pathComponents.last, lastPathComponent != "client" {
// try to get the client in sync with the server on errors if the original request wasn't a get/create client
_ = try? await Client.get()
}
return true
}

return false
}

Expand Down

0 comments on commit 860b3a5

Please sign in to comment.