mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-27 20:36:16 +02:00
a special error for when payments fail.
This commit is contained in:
@@ -29,6 +29,10 @@ from .crud import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentFailure(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
async def create_invoice(
|
async def create_invoice(
|
||||||
*,
|
*,
|
||||||
wallet_id: str,
|
wallet_id: str,
|
||||||
@@ -162,8 +166,9 @@ async def pay_invoice(
|
|||||||
)
|
)
|
||||||
await delete_payment(temp_id, conn=conn)
|
await delete_payment(temp_id, conn=conn)
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise PaymentFailure(
|
||||||
payment.error_message or "Failed to pay_invoice on backend."
|
payment.error_message
|
||||||
|
or "Payment failed, but backend didn't give us an error message."
|
||||||
)
|
)
|
||||||
|
|
||||||
return invoice.payment_hash
|
return invoice.payment_hash
|
||||||
|
@@ -12,7 +12,7 @@ from lnbits import bolt11
|
|||||||
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
||||||
|
|
||||||
from .. import core_app, db
|
from .. import core_app, db
|
||||||
from ..services import create_invoice, pay_invoice, perform_lnurlauth
|
from ..services import PaymentFailure, create_invoice, pay_invoice, perform_lnurlauth
|
||||||
from ..tasks import sse_listeners
|
from ..tasks import sse_listeners
|
||||||
|
|
||||||
|
|
||||||
@@ -127,6 +127,8 @@ async def api_payments_pay_invoice():
|
|||||||
return jsonify({"message": str(e)}), HTTPStatus.BAD_REQUEST
|
return jsonify({"message": str(e)}), HTTPStatus.BAD_REQUEST
|
||||||
except PermissionError as e:
|
except PermissionError as e:
|
||||||
return jsonify({"message": str(e)}), HTTPStatus.FORBIDDEN
|
return jsonify({"message": str(e)}), HTTPStatus.FORBIDDEN
|
||||||
|
except PaymentFailure as e:
|
||||||
|
return jsonify({"message": str(e)}), 520
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user