Skip to content

Commit

Permalink
fix(DataStore): retry on session expired requests
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmicha committed Jan 18, 2024
1 parent 3d142c1 commit 417efad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,18 @@ class SyncMutationToCloudOperation: AsynchronousOperation {
advice = shouldRetryWithDifferentAuthType()
// should retry with a different authType if request failed locally with an AuthError
case .operationError(_, _, let error) where (error as? AuthError) != nil:
advice = shouldRetryWithDifferentAuthType()


// Not all AuthError's are unauthorized errors. If `AuthError.sessionExpired` then
// the request never made it to the server. We should keep trying until the user is signed in.
// Otherwise we may be making the wrong determination to remove this mutation event.
if case .sessionExpired = error as? AuthError {
// Use `userAuthenticationRequired` to ensure advice to retry is true.
advice = requestRetryablePolicy.retryRequestAdvice(urlError: URLError(.userAuthenticationRequired),
httpURLResponse: nil,
attemptNumber: currentAttemptNumber)
} else {
advice = shouldRetryWithDifferentAuthType()
}
case .httpStatusError(_, let httpURLResponse):
advice = requestRetryablePolicy.retryRequestAdvice(urlError: nil,
httpURLResponse: httpURLResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class RequestRetryablePolicy: RequestRetryable {
.timedOut,
.dataNotAllowed,
.cannotParseResponse,
.networkConnectionLost:
.networkConnectionLost,
.userAuthenticationRequired:
let waitMillis = retryDelayInMillseconds(for: attemptNumber)
return RequestRetryAdvice(shouldRetry: true, retryInterval: .milliseconds(waitMillis))
default:
Expand Down

0 comments on commit 417efad

Please sign in to comment.