From 8e06bef3b9826d18a5682f8ec1fb3b1182a04412 Mon Sep 17 00:00:00 2001 From: Overtorment Date: Fri, 24 Jan 2020 21:19:54 +0000 Subject: [PATCH] REF: better error handling --- controllers/api.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/controllers/api.js b/controllers/api.js index 8db0ba7..eec85f1 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -131,7 +131,14 @@ router.post('/payinvoice', async function(req, res) { return errorTryAgainLater(res); } - let userBalance = await u.getCalculatedBalance(); + let userBalance; + try { + userBalance = await u.getCalculatedBalance(); + } catch (Error) { + logger.log('', [req.id, 'error running getCalculatedBalance():', Error]); + lock.releaseLock(); + return errorTryAgainLater(res); + } lightning.decodePayReq({ pay_req: req.body.invoice }, async function(err, info) { if (err) { @@ -206,7 +213,7 @@ router.post('/payinvoice', async function(req, res) { return errorPaymentFailed(res); } }); - if (!info.num_satoshis && !info.num_satoshis) { + if (!info.num_satoshis) { // tip invoice, but someone forgot to specify amount await lock.releaseLock(); return errorBadArguments(res);