Skip to content

Commit

Permalink
dont sync client if client call failed, add retry (#76)
Browse files Browse the repository at this point in the history
* dont sync client if client call failed, add retry

* update comment
  • Loading branch information
mikepitre authored Jul 6, 2024
1 parent 69bd8c5 commit 1a9d7de
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 Client.get()
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 client
_ = try? await Client.get()
}
return true
}

return false
}

Expand Down

0 comments on commit 1a9d7de

Please sign in to comment.