From c80c42b2dafe4b49d2aa7827894878f91da2dd69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Tu=E1=BA=A5n=20D=C5=A9ng?= Date: Mon, 1 Apr 2019 20:53:39 +0700 Subject: [PATCH] Completely handle all unhandled promise in db --- src/data/database.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/data/database.js b/src/data/database.js index c4921572..7f7e936f 100644 --- a/src/data/database.js +++ b/src/data/database.js @@ -356,9 +356,14 @@ function readSubmission(sub_id) { reject(new Error(`Invalid Submission's ID: ${sub_id}`)); else readUserByID(docs.user_id) - .then((res) => { - docs.username = res.username; - }) + .then( + (res) => { + docs.username = res.username; + }, + () => { + docs.username = null; + } + ) .finally(() => { resolve(docs); }); @@ -432,9 +437,14 @@ function readSubmissionSrc(sub_id) { reject(new Error(`Invalid Submission's ID: ${sub_id}`)); else readUserByID(docs.user_id) - .then((res) => { - docs.username = res.username; - }) + .then( + (res) => { + docs.username = res.username; + }, + () => { + docs.username = null; + } + ) .finally(() => { resolve(docs); });