aboutsummaryrefslogtreecommitdiffstats
path: root/src/lnurl.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-30 18:03:33 +0000
committerAdam Soltys <[email protected]>2026-09-30 18:03:33 +0000
commit0570f48910ddc4ea10d27fb8ab7992fbd013a0b7 (patch)
treedbc1e5ece94bc71fcd8bb7e89f61043933c1992c /src/lnurl.js
parent95eaf11d116260b101c81346ba41810aacf49a7d (diff)
parentcfeacb1a7a10766565ed3eaab13154096478c837 (diff)
downloadcoinosv3-0570f48910ddc4ea10d27fb8ab7992fbd013a0b7.tar.gz
coinosv3-0570f48910ddc4ea10d27fb8ab7992fbd013a0b7.zip
Merge remote-tracking branch 'cs/prod'
Diffstat (limited to 'src/lnurl.js')
-rw-r--r--src/lnurl.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/lnurl.js b/src/lnurl.js
index f641707..3f1b39b 100644
--- a/src/lnurl.js
+++ b/src/lnurl.js
@@ -68,13 +68,26 @@ export function zapTargetFromProfile(profile, pk) {
function safeEncode(url) { try { return encodeLnurl(url); } catch { return null; } }
+// Errors name the server: the recipient's Lightning address lives on THEIR
+// host, and a bare "signal is aborted without reason" (the browser's words
+// for our timeout) read as though the wallet had broken.
async function fetchJson(url, ms = 8000) {
const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), ms);
+ let host = 'their Lightning server';
+ try { host = new URL(url).host; } catch {}
try {
const r = await fetch(url, { signal: ctrl.signal, headers: { Accept: 'application/json' } });
- if (!r.ok) throw new Error(`HTTP ${r.status}`);
+ if (!r.ok) {
+ // LNURL servers say why in a JSON { status: 'ERROR', reason } body
+ const reason = await r.json().then((d) => d && d.reason).catch(() => null);
+ throw new Error(reason ? `${host}: ${reason}` : `${host} answered with an error (HTTP ${r.status})`);
+ }
return await r.json();
+ } catch (e) {
+ if (ctrl.signal.aborted || e?.name === 'AbortError') throw new Error(`${host} didn’t answer in ${Math.round(ms / 1000)}s — their Lightning address may be down`);
+ if (e instanceof TypeError) throw new Error(`couldn’t reach ${host}`);
+ throw e;
} finally { clearTimeout(timer); }
}