From c140aa58db228f7d274038444b707694c8fcc3b8 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sat, 16 May 2020 22:52:30 +0200 Subject: [PATCH] - Refactored some error handling on schools router --- routes/schools.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/routes/schools.js b/routes/schools.js index 9435e0c..1c79359 100644 --- a/routes/schools.js +++ b/routes/schools.js @@ -30,10 +30,9 @@ const getSchools = () => { reject(new HttpError(500, 'Error: Database error')) } else if (result.length == 0) { reject(new HttpError(404, 'Error: No ressource matching this id')) - } else { - result = await buildSchool(result[0]) - resolve(result); } + result = await buildSchool(result[0]) + resolve(result); }) }) .catch(err => { throw err }) @@ -59,7 +58,9 @@ const getSchool = (id) => { let query = "SELECT * FROM school WHERE id = " + db.escape(id) db.query(query, async (err, result) => { - if (err) return reject + if (err) { + reject(new HttpError(500, 'Error: Database error')) + } result = await buildSchool(result[0]) resolve(result); })