From f695cbd6d1ed9d8560363693c0f3bdcb7c78c7d8 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 3 May 2023 17:26:45 +0000 Subject: error handling --- routes/lnurl.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'routes/lnurl.js') diff --git a/routes/lnurl.js b/routes/lnurl.js index 5cfb26bb..14f848a4 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -34,11 +34,15 @@ export default { }, async decode({ query: { text } }, res) { - let url = Buffer.from( - bech32.fromWords(bech32.decode(text, 20000).words) - ).toString(); + try { + let url = Buffer.from( + bech32.fromWords(bech32.decode(text, 20000).words) + ).toString(); - res.send(await got(url).json()); + res.send(await got(url).json()); + } catch (e) { + bail(res, e.message); + } }, async lnurlp({ params: { username } }, res) { @@ -92,7 +96,7 @@ export default { let uid = await g(`lnurl:${id}`); let user = await g(`user:${uid}`); let { username } = user; - username = username.replace(/\s/g, '').toLowerCase(); + username = username.replace(/\s/g, "").toLowerCase(); let metadata = JSON.stringify([ ["text/plain", `Paying ${username}@${host}`], -- cgit v1.2.3