From ee68bd294661417c6be99291d54b4568dea81bd9 Mon Sep 17 00:00:00 2001 From: keyan Date: Mon, 18 Dec 2023 18:02:39 -0600 Subject: [PATCH] hide lnurlpay errors while still reporting errors accurately --- api/resolvers/serial.js | 5 +++-- pages/api/lnurlp/[username]/pay.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/resolvers/serial.js b/api/resolvers/serial.js index 6b2b9372..3731e490 100644 --- a/api/resolvers/serial.js +++ b/api/resolvers/serial.js @@ -3,7 +3,8 @@ import retry from 'async-retry' import Prisma from '@prisma/client' import { settleHodlInvoice } from 'ln-service' import { createHmac } from './wallet' -import { msatsToSats } from '../../lib/format' +import { msatsToSats, numWithUnits } from '../../lib/format' +import { BALANCE_LIMIT_MSATS } from '../../lib/constants' export default async function serialize (models, ...calls) { return await retry(async bail => { @@ -48,7 +49,7 @@ export default async function serialize (models, ...calls) { bail(new Error('too many pending invoices')) } if (error.message.includes('SN_INV_EXCEED_BALANCE')) { - bail(new Error('too many pending invoices')) + bail(new Error(`pending invoices must not cause balance to exceed ${numWithUnits(msatsToSats(BALANCE_LIMIT_MSATS))}`)) } if (error.message.includes('40001') || error.code === 'P2034') { throw new Error('wallet balance serialization failure - try again') diff --git a/pages/api/lnurlp/[username]/pay.js b/pages/api/lnurlp/[username]/pay.js index 1347ce20..df130fe2 100644 --- a/pages/api/lnurlp/[username]/pay.js +++ b/pages/api/lnurlp/[username]/pay.js @@ -91,6 +91,6 @@ export default async ({ query: { username, amount, nostr, comment, payerdata: pa }) } catch (error) { console.log(error) - res.status(400).json({ status: 'ERROR', reason: error.message }) + res.status(400).json({ status: 'ERROR', reason: 'could not generate invoice' }) } }