fix: handle all lnurl exceptions on lnurlscan endpoint (#3451)

This commit is contained in:
dni ⚡ 2025-10-30 08:07:25 +01:00 committed by GitHub
parent ca8264b1f5
commit 2856803ca7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,16 +6,17 @@ from fastapi import (
Depends, Depends,
HTTPException, HTTPException,
) )
from lnurl import LnurlResponseException from lnurl import (
from lnurl import execute_login as lnurlauth
from lnurl import handle as lnurl_handle
from lnurl.models import (
LnurlAuthResponse, LnurlAuthResponse,
LnurlErrorResponse, LnurlErrorResponse,
LnurlException,
LnurlPayResponse, LnurlPayResponse,
LnurlResponseModel, LnurlResponseException,
LnurlWithdrawResponse, LnurlWithdrawResponse,
) )
from lnurl import execute_login as lnurlauth
from lnurl import handle as lnurl_handle
from lnurl.models import LnurlResponseModel
from loguru import logger from loguru import logger
from lnbits.core.models import Payment from lnbits.core.models import Payment
@ -38,7 +39,7 @@ async def _handle(lnurl: str) -> LnurlResponseModel:
res = await lnurl_handle(lnurl, user_agent=settings.user_agent, timeout=5) res = await lnurl_handle(lnurl, user_agent=settings.user_agent, timeout=5)
if isinstance(res, LnurlErrorResponse): if isinstance(res, LnurlErrorResponse):
raise HTTPException(status_code=HTTPStatus.BAD_REQUEST, detail=res.reason) raise HTTPException(status_code=HTTPStatus.BAD_REQUEST, detail=res.reason)
except LnurlResponseException as exc: except LnurlException as exc:
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST, detail=str(exc) status_code=HTTPStatus.BAD_REQUEST, detail=str(exc)
) from exc ) from exc