From ee9b25a0a893436eed042522966d1cefceeca4f7 Mon Sep 17 00:00:00 2001 From: t123yh Date: Sun, 3 Sep 2017 15:50:58 +0800 Subject: [PATCH] Fix error handling. --- modules/api.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/api.js b/modules/api.js index 9e98420..60ef4fc 100644 --- a/modules/api.js +++ b/modules/api.js @@ -35,7 +35,7 @@ app.post('/api/login', async (req, res) => { res.setHeader('Content-Type', 'application/json'); let user = await User.fromName(req.body.username); - if (!user) res.send({ error_code: 1001 }); + if (!user) throw 1001; else if (user.password == null || user.password === '') res.send({ error_code: 1003 }); else if (user.password !== req.body.password) res.send({ error_code: 1002 }); else { @@ -53,7 +53,7 @@ app.post('/api/forget', async (req, res) => { try { res.setHeader('Content-Type', 'application/json'); let user = await User.fromEmail(req.body.email); - if (!user) res.send({ error_code: 1001 }); + if (!user) throw 1001; let sendObj = { userId: user.id, }; @@ -74,6 +74,7 @@ app.post('/api/forget', async (req, res) => { error_code: 2010, message: require('util').inspect(e) }); + return null; } res.send({ error_code: 1 });