From c03559bd7285d6608974ab02be78b859a6cac689 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 29 Apr 2020 14:16:09 -0700 Subject: catch account shift errors --- routes/users.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/routes/users.js b/routes/users.js index 82f4264a..6b814e81 100644 --- a/routes/users.js +++ b/routes/users.js @@ -375,16 +375,21 @@ app.post("/shiftAccount", auth, async (req, res) => { let { user } = req; let { asset } = req.body; - const account = await db.Account.findOne({ - where: { user_id: user.id, asset } - }); + try { + const account = await db.Account.findOne({ + where: { user_id: user.id, asset } + }); - user.account_id = account.id; - await user.save(); - - user = await getUser(user.username); - emit(user.username, "user", user); - res.send(account); + user.account_id = account.id; + await user.save(); + + user = await getUser(user.username); + emit(user.username, "user", user); + res.send(account); + } catch(e) { + l.error(e.message); + return res.status(500).send("There was a problem switching accounts"); + } }); setInterval(() => (faucet = 2000), DAY); -- cgit v1.2.3