Skip to content

Commit

Permalink
Protect against missing non-existent snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbianca committed May 7, 2019
1 parent eaecf9c commit ccf3616
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions database/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export const snapshotToData = (
snapshot: database.DataSnapshot,
keyField?: string
) => {
if (!snapshot.exists) {
return null;
}

const val = snapshot.val();
if (isObject(val)) {
return {
Expand Down
5 changes: 4 additions & 1 deletion firestore/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ export const snapshotToData = (
snapshot: firestore.DocumentSnapshot,
idField?: string
) => {
if (!snapshot.exists) return null;
if (!snapshot.exists) {
return null;
}

return {
...snapshot.data(),
...(idField ? { [idField]: snapshot.id } : null),
Expand Down

0 comments on commit ccf3616

Please sign in to comment.