Skip to content

Commit 2ed82c7

Browse files
authored
Merge branch 'fix/gh-3259' into modifying-retryable-error-datastore
2 parents 40ffbbd + 417efad commit 2ed82c7

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/SyncMutationToCloudOperation.swift

+12-2
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,18 @@ class SyncMutationToCloudOperation: AsynchronousOperation {
294294
advice = shouldRetryWithDifferentAuthType()
295295
// should retry with a different authType if request failed locally with an AuthError
296296
case .operationError(_, _, let error) where (error as? AuthError) != nil:
297-
advice = shouldRetryWithDifferentAuthType()
298-
297+
298+
// Not all AuthError's are unauthorized errors. If `AuthError.sessionExpired` then
299+
// the request never made it to the server. We should keep trying until the user is signed in.
300+
// Otherwise we may be making the wrong determination to remove this mutation event.
301+
if case .sessionExpired = error as? AuthError {
302+
// Use `userAuthenticationRequired` to ensure advice to retry is true.
303+
advice = requestRetryablePolicy.retryRequestAdvice(urlError: URLError(.userAuthenticationRequired),
304+
httpURLResponse: nil,
305+
attemptNumber: currentAttemptNumber)
306+
} else {
307+
advice = shouldRetryWithDifferentAuthType()
308+
}
299309
case .httpStatusError(_, let httpURLResponse):
300310
advice = requestRetryablePolicy.retryRequestAdvice(urlError: nil,
301311
httpURLResponse: httpURLResponse,

AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RequestRetryablePolicy.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class RequestRetryablePolicy: RequestRetryable {
4141
.dataNotAllowed,
4242
.cannotParseResponse,
4343
.networkConnectionLost,
44-
.secureConnectionFailed:
44+
.secureConnectionFailed,
45+
.userAuthenticationRequired:
4546
let waitMillis = retryDelayInMillseconds(for: attemptNumber)
4647
return RequestRetryAdvice(shouldRetry: true, retryInterval: .milliseconds(waitMillis))
4748
default:

0 commit comments

Comments
 (0)