-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(DataStore): retry on session expired requests #3477
Conversation
@@ -40,7 +40,8 @@ class RequestRetryablePolicy: RequestRetryable { | |||
.timedOut, | |||
.dataNotAllowed, | |||
.cannotParseResponse, | |||
.networkConnectionLost: | |||
.networkConnectionLost, | |||
.userAuthenticationRequired: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have a unit test for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added!
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #3477 +/- ##
==========================================
+ Coverage 67.89% 68.03% +0.13%
==========================================
Files 1079 1069 -10
Lines 36359 36010 -349
==========================================
- Hits 24687 24498 -189
+ Misses 11672 11512 -160
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
… update retry mechanism for error codes (#3479) * fix(DataStore): retry on session expired requests * fix(datastore): Adding secureConnectionFailed as a retryable error (#3475) * fix(datastore): decode optimistically with paginated list response type (#3474) * fix(datastore): decode optimistically with paginated list response type * add unit test cases * resolve comments * Update PaginatedListTests.swift * fix(DataStore): retry on session expired requests (#3477) * fix(DataStore): retry on session expired requests * add test --------- Co-authored-by: Michael Law <[email protected]> Co-authored-by: Harsh <[email protected]> Co-authored-by: Di Wu <[email protected]>
Issue #
#3259
More specifically #3259 (comment)
Description
An expired token will be refreshed automatically when Amplify.API retrieves the token from the token provider, via Amplify.Auth. At this point, it should refresh the token if it is expired. When the token cannot be refreshed because the Refresh token is expired, then API receives an AuthError, which is wrapped in an
APIError.operationError
. The user needs to sign in again.DataStore's SyncMutationToCloudOperation uses Amplify.API to make the user pool auth request and receives
API.opeationError(,,AuthError.sessionExpired)
error. When the session is expired, DataStore shouldn't delete mutation event because the request never made it to the service to perform the authorization check. The PR adds a check for session expired errors and goes into the exponential retry state.Once the user signs in, and the mutation event gets sent on the next retry, then the response will be handled as normally. Mutation events should only be deleted if the response is Unauthorized, by calling
errorHandler
to notify the developer that we're dropping the event, then deleting it.General Checklist
Given When Then
inline code documentation and are named accordinglytestThing_condition_expectation()
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.