return proper error codes on /lnurlscan

so the notification works.
This commit is contained in:
fiatjaf 2020-10-20 23:19:22 -03:00
parent 52619ecc0f
commit 85ec111ff0
2 changed files with 8 additions and 5 deletions

View File

@ -19,7 +19,7 @@ from .crud import get_wallet, create_payment, delete_payment, check_internal, up
def create_invoice( def create_invoice(
*, *,
wallet_id: str, wallet_id: str,
amount: int, amount: int, # in satoshis
memo: str, memo: str,
description_hash: Optional[bytes] = None, description_hash: Optional[bytes] = None,
extra: Optional[Dict] = None, extra: Optional[Dict] = None,

View File

@ -297,21 +297,24 @@ async def api_lnurlscan(code: str):
domain = urlparse(url.url).netloc domain = urlparse(url.url).netloc
if url.is_login: if url.is_login:
return jsonify({"domain": domain, "kind": "auth", "error": "unsupported"}) return jsonify({"domain": domain, "kind": "auth", "error": "unsupported"}), HTTPStatus.BAD_REQUEST
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
r = await client.get(url.url, timeout=40) r = await client.get(url.url, timeout=40)
if r.is_error: if r.is_error:
return jsonify({"domain": domain, "error": "failed to get parameters"}) return jsonify({"domain": domain, "error": "failed to get parameters"}), HTTPStatus.SERVICE_UNAVAILABLE
try: try:
jdata = json.loads(r.text) jdata = json.loads(r.text)
data: lnurl.LnurlResponseModel = lnurl.LnurlResponse.from_dict(jdata) data: lnurl.LnurlResponseModel = lnurl.LnurlResponse.from_dict(jdata)
except (json.decoder.JSONDecodeError, lnurl.exceptions.LnurlResponseException): except (json.decoder.JSONDecodeError, lnurl.exceptions.LnurlResponseException):
return jsonify({"domain": domain, "error": f"got invalid response '{r.text[:200]}'"}) return (
jsonify({"domain": domain, "error": f"got invalid response '{r.text[:200]}'"}),
HTTPStatus.SERVICE_UNAVAILABLE,
)
if type(data) is lnurl.LnurlChannelResponse: if type(data) is lnurl.LnurlChannelResponse:
return jsonify({"domain": domain, "kind": "channel", "error": "unsupported"}) return jsonify({"domain": domain, "kind": "channel", "error": "unsupported"}), HTTPStatus.BAD_REQUEST
params: Dict = data.dict() params: Dict = data.dict()
if type(data) is lnurl.LnurlWithdrawResponse: if type(data) is lnurl.LnurlWithdrawResponse: