Skip to content

Commit

Permalink
Merge pull request #71 from vnma0/70-fix
Browse files Browse the repository at this point in the history
Patch unhandled promise in readAllSubmissions
  • Loading branch information
dungwinux authored Apr 1, 2019
2 parents 1817872 + f41544b commit 68aabe8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/data/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,11 @@ async function readAllSubmissions(page, size, count) {
// TODO: Decide what to do when there's invalid user
// Currently, it will throw error with invalid user_id
if (err) reject(err);
else
Promise.all(
docs.map((doc) => readUserByID(doc.user_id))
).then((usernameList) => {
else {
let usernameListPromise = docs.map((doc) =>
readUserByID(doc.user_id).catch(() => null)
);
Promise.all(usernameListPromise).then((usernameList) => {
let serialized = docs.map((doc, idx) => {
doc.username = usernameList[idx].username;
return doc;
Expand All @@ -325,6 +326,7 @@ async function readAllSubmissions(page, size, count) {
count: count
});
});
}
});
});
}
Expand Down

0 comments on commit 68aabe8

Please sign in to comment.