fix perform_lnurl error handling.

This commit is contained in:
fiatjaf 2020-11-10 23:01:55 -03:00
parent d4e30356c7
commit bb94dc6526
3 changed files with 20 additions and 17 deletions

View File

@ -5,8 +5,8 @@ from binascii import unhexlify
from typing import Optional, Tuple, Dict
from urllib.parse import urlparse, parse_qs
from quart import g
from lnurl import LnurlWithdrawResponse # type: ignore
from ecdsa.util import sigencode_der # type: ignore
from lnurl import LnurlErrorResponse, LnurlWithdrawResponse # type: ignore
try:
from typing import TypedDict # type: ignore
@ -159,7 +159,7 @@ async def redeem_lnurl_withdraw(wallet_id: str, res: LnurlWithdrawResponse, memo
)
async def perform_lnurlauth(callback: str):
async def perform_lnurlauth(callback: str) -> Optional[LnurlErrorResponse]:
k1 = unhexlify(parse_qs(urlparse(callback).query)["k1"][0])
key = g.wallet.lnurlauth_key
sig = key.sign_digest_deterministic(k1, sigencode=sigencode_der)
@ -178,11 +178,11 @@ async def perform_lnurlauth(callback: str):
if resp["status"] == "OK":
return None
return resp["reason"]
return LnurlErrorResponse(reason=resp["reason"])
except (KeyError, json.decoder.JSONDecodeError):
return r.text[:200] + "..." if len(r.text) > 200 else r.text
return None
return LnurlErrorResponse(
reason=r.text[:200] + "..." if len(r.text) > 200 else r.text,
)
def check_invoice_status(wallet_id: str, payment_hash: str) -> PaymentStatus:

View File

@ -565,12 +565,16 @@ new Vue({
})
.catch(err => {
dismissAuthMsg()
this.$q.notify({
message: `Authentication failed. ${this.parse.lnurlauth.domain} says:`,
caption: err.response.data.message,
type: 'warning',
timeout: 5000
})
if (err.response.data.reason) {
this.$q.notify({
message: `Authentication failed. ${this.parse.lnurlauth.domain} says:`,
caption: err.response.data.reason,
type: 'warning',
timeout: 5000
})
} else {
LNbits.utils.notifyApiError(err)
}
})
},
deleteWallet: function (walletId, user) {

View File

@ -367,8 +367,7 @@ async def api_lnurlscan(code: str):
}
)
async def api_perform_lnurlauth():
try:
await perform_lnurlauth(g.data["callback"])
return "", HTTPStatus.OK
except Exception as exc:
return jsonify({"message": str(exc)}), HTTPStatus.SERVICE_UNAVAILABLE
err = await perform_lnurlauth(g.data["callback"])
if err:
return jsonify({"reason": err.reason}), HTTPStatus.SERVICE_UNAVAILABLE
return "", HTTPStatus.OK