Skip to content

Commit

Permalink
fix: show LNURL errors (#3090)
Browse files Browse the repository at this point in the history
* fix: throw actual error reason and messages to screen

* fix: harmonize error messages for non 200 responses

---------

Co-authored-by: René Aaron <[email protected]>
  • Loading branch information
pavanjoshi914 and reneaaron authored Mar 18, 2024
1 parent 5ea210a commit 760887d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/common/lib/lnurl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import axios from "axios";
import lightningPayReq from "bolt11";
import { isLNURLDetailsError } from "~/common/utils/typeHelpers";
import {
LNURLAuthServiceResponse,
LNURLDetails,
LNURLError,
LNURLAuthServiceResponse,
LNURLPaymentInfo,
} from "~/types";

Expand Down Expand Up @@ -97,19 +97,23 @@ const lnurl = {
const lnurlDetails = data;

if (isLNURLDetailsError(lnurlDetails)) {
throw new Error(`LNURL Error: ${lnurlDetails.reason}`);
throw new Error(lnurlDetails.reason);
} else {
lnurlDetails.domain = url.hostname;
lnurlDetails.url = url.toString();
}

return lnurlDetails;
} catch (e) {
throw new Error(
`Connection problem or invalid lnurl / lightning address: ${
e instanceof Error ? e.message : ""
}`
);
let error = "";
if (axios.isAxiosError(e)) {
error =
(e.response?.data as { reason?: string })?.reason || e.message;
} else if (e instanceof Error) {
error = e.message;
}

throw new Error(error);
}
}
},
Expand Down

0 comments on commit 760887d

Please sign in to comment.