fix: error handling (#3214)

This commit is contained in:
Tiago Vasconcelos 2025-06-24 16:27:28 +01:00 committed by GitHub
parent b1a09af82c
commit 7c0a955b30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 9 deletions

View file

@ -130,14 +130,20 @@ async def api_lnurlscan(
headers = {"User-Agent": settings.user_agent} headers = {"User-Agent": settings.user_agent}
async with httpx.AsyncClient(headers=headers, follow_redirects=True) as client: async with httpx.AsyncClient(headers=headers, follow_redirects=True) as client:
check_callback_url(url) check_callback_url(url)
r = await client.get(url, timeout=5) try:
r.raise_for_status() r = await client.get(url, timeout=5)
if r.is_error: r.raise_for_status()
except httpx.HTTPStatusError as exc:
if exc.response.status_code == 404:
raise HTTPException(HTTPStatus.NOT_FOUND, "Not found") from exc
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.SERVICE_UNAVAILABLE, status_code=HTTPStatus.SERVICE_UNAVAILABLE,
detail={"domain": domain, "message": "failed to get parameters"}, detail={
) "domain": domain,
"message": "failed to get parameters",
},
) from exc
try: try:
data = json.loads(r.text) data = json.loads(r.text)
except json.decoder.JSONDecodeError as exc: except json.decoder.JSONDecodeError as exc:

View file

@ -338,9 +338,6 @@ window.WalletPageLogic = {
'/api/v1/lnurlscan/' + this.parse.data.request, '/api/v1/lnurlscan/' + this.parse.data.request,
this.g.wallet.adminkey this.g.wallet.adminkey
) )
.catch(err => {
LNbits.utils.notifyApiError(err)
})
.then(response => { .then(response => {
const data = response.data const data = response.data
@ -378,6 +375,9 @@ window.WalletPageLogic = {
} }
} }
}) })
.catch(err => {
LNbits.utils.notifyApiError(err)
})
}, },
decodeQR(res) { decodeQR(res) {
this.parse.data.request = res[0].rawValue this.parse.data.request = res[0].rawValue