Skip to content
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(@aws-amplify/datastore): handle sync query unauthorized #7926

Merged
merged 1 commit into from
Mar 12, 2021

Conversation

iartemiev
Copy link
Member

@iartemiev iartemiev commented Mar 12, 2021

Fixes a bug where the sync engine breaks when a sync query returns an unauthorized error.
The expected behavior for DataStore is that an unauthorized error on a model should not break syncing for other models.

Currently, when a sync query request returns unauthorized, we get the following unhandled error

error on  TypeError: Cannot read property 'items' of null

on this line.

An unauthorized query response typically won't return any items, so this PR adds a check to see if items are defined before attempting to iterate over them. If not defined, we return an empty list (items: []) and nextToken: null to signal to the retrievePage method that it shouldn't attempt to retrieve additional pages via this query.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@amhinson amhinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Contributor

@manueliglesias manueliglesias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@iartemiev iartemiev merged commit 4b37112 into aws-amplify:main Mar 12, 2021
@iartemiev iartemiev deleted the ds-sync-query-unauthed branch March 12, 2021 16:45
This was referenced Mar 13, 2021
This was referenced Mar 15, 2021
dgonsan pushed a commit to dgonsan/amplify-js that referenced this pull request Mar 18, 2021
@github-actions
Copy link

This pull request has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants