Skip to content

Commit

Permalink
fix(@aws-amplify/datastore): handle sync query unauthorized (aws-ampl…
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev authored and Daniel Gonzalez committed Mar 18, 2021
1 parent 3ed769b commit 622a84f
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions packages/datastore/src/sync/processors/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ class SyncProcessor {
variables,
});
} catch (error) {
if (this.partialDataFeatureFlagEnabled()) {
const hasItems = Boolean(
error &&
error.data &&
error.data[opName] &&
error.data[opName].items
);
const hasItems = Boolean(
error &&
error.data &&
error.data[opName] &&
error.data[opName].items
);

if (this.partialDataFeatureFlagEnabled()) {
if (hasItems) {
const result = error;
result.data[opName].items = result.data[opName].items.filter(
Expand Down Expand Up @@ -178,12 +178,26 @@ class SyncProcessor {
);
if (unauthorized) {
const result = error;
result.data[opName].items = result.data[opName].items.filter(
item => item !== null
);

const opResultDefaults = {
items: [],
nextToken: null,
startedAt: null,
};

if (hasItems) {
result.data[opName].items = result.data[opName].items.filter(
item => item !== null
);
} else {
result.data[opName] = {
...opResultDefaults,
...result.data[opName],
};
}
logger.warn(
'queryError',
'User is unauthorized, some items could not be returned.'
`User is unauthorized to query ${opName}, some items could not be returned.`
);
return result;
} else {
Expand Down

0 comments on commit 622a84f

Please sign in to comment.