diff options
| author | Adam Soltys <[email protected]> | 2023-04-04 22:12:49 +0000 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-04-04 22:12:56 +0000 |
| commit | 924c83701a02f043041d7dbb27ce8d77c6829c6b (patch) | |
| tree | 11c1e041c94d5154830b98d938847bb79791e0aa | |
| parent | a650cf9a37e4536d3ce5c2bfb346b1056b596f09 (diff) | |
| download | coinos-server-924c83701a02f043041d7dbb27ce8d77c6829c6b.tar.gz coinos-server-924c83701a02f043041d7dbb27ce8d77c6829c6b.zip | |
catch lnurlp errors
| -rw-r--r-- | routes/lnurl.js | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/routes/lnurl.js b/routes/lnurl.js index e31d24e2..1f45627b 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -42,42 +42,47 @@ export default { }, async lnurlp({ params: { username } }, res) { - let { id: uid } = await getUser(username); - if (!uid) { - let u = await got(`${classic}/admin/migrate/${username}?zero=true`, { - headers: { authorization: `Bearer ${admin}` }, - }).json(); + try { + let { id: uid } = await getUser(username); + if (!uid) { + let u = await got(`${classic}/admin/migrate/${username}?zero=true`, { + headers: { authorization: `Bearer ${admin}` }, + }).json(); - if (!u) fail("user not found"); - let { balance, pubkey } = u; + if (!u) fail("user not found"); + let { balance, pubkey } = u; - uid = u.uuid; + uid = u.uuid; - u = { id: uid, about: u.address, ...pick(u, fields) }; - delete u.address; + u = { id: uid, about: u.address, ...pick(u, fields) }; + delete u.address; - await s(`user:${username.replace(/\s/g, "").toLowerCase()}`, uid); - await s(`user:${uid}`, u); - await s(`balance:${uid}`, balance); + await s(`user:${username.replace(/\s/g, "").toLowerCase()}`, uid); + await s(`user:${uid}`, u); + await s(`balance:${uid}`, balance); - l("added missing user", username); - } + l("added missing user", username); + } - let metadata = JSON.stringify([ - ["text/plain", `Paying ${username}@${host}`], - ["text/identifier", `${username}@${host}`], - ]); + let metadata = JSON.stringify([ + ["text/plain", `Paying ${username}@${host}`], + ["text/identifier", `${username}@${host}`], + ]); - let id = v4(); - await s(`lnurl:${id}`, uid); + let id = v4(); + await s(`lnurl:${id}`, uid); - res.send({ - minSendable: 1000, - maxSendable: 100000000000, - metadata, - callback: `${URL}/api/lnurl/${id}`, - tag: "payRequest", - }); + res.send({ + minSendable: 1000, + maxSendable: 100000000000, + metadata, + callback: `${URL}/api/lnurl/${id}`, + tag: "payRequest", + }); + } catch (e) { + warn("problem generating lnurlp request", e.message); + bail(res, e.message); + } }, async lnurl({ params: { id }, query: { amount } }, res) { |
