fix: error handling (#3214)
This commit is contained in:
parent
b1a09af82c
commit
7c0a955b30
2 changed files with 15 additions and 9 deletions
|
|
@ -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)
|
||||||
|
try:
|
||||||
r = await client.get(url, timeout=5)
|
r = await client.get(url, timeout=5)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
if r.is_error:
|
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:
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue