FIX: potential crash

This commit is contained in:
Overtorment 2019-01-06 12:44:41 +00:00
parent 130a8dc773
commit a42d331e38

View File

@ -116,6 +116,8 @@ router.post('/payinvoice', async function(req, res) {
let userBalance = await u.getBalance(); let userBalance = await u.getBalance();
try {
// TODO: refactor
lightning.decodePayReq({ pay_req: req.body.invoice }, async function(err, info) { lightning.decodePayReq({ pay_req: req.body.invoice }, async function(err, info) {
if (err) return errorNotAValidInvoice(res); if (err) return errorNotAValidInvoice(res);
@ -172,6 +174,7 @@ router.post('/payinvoice', async function(req, res) {
}); });
let inv = { payment_request: req.body.invoice, amt: info.num_satoshis }; // amt is used only for 'tip' invoices let inv = { payment_request: req.body.invoice, amt: info.num_satoshis }; // amt is used only for 'tip' invoices
try { try {
logger.log('/payinvoice', [req.id, 'before write', JSON.stringify(inv)]);
call.write(inv); call.write(inv);
} catch (Err) { } catch (Err) {
logger.log('/payinvoice', [req.id, 'exception', JSON.stringify(Err)]); logger.log('/payinvoice', [req.id, 'exception', JSON.stringify(Err)]);
@ -181,6 +184,9 @@ router.post('/payinvoice', async function(req, res) {
return errorNotEnougBalance(res); return errorNotEnougBalance(res);
} }
}); });
} catch (Err) {
return errorLnd(res);
}
}); });
router.get('/getbtc', async function(req, res) { router.get('/getbtc', async function(req, res) {