feat: add generic lnurl error response handler (#2638)
* feat: add generic lnurl error response handler this is used multiple times in extensions to safeguard `views_lnurl.py` endpoint to not return a wrong lnurl error response. you use it by just setting following on your lnurl router/view ``` withdraw_ext_lnurl = APIRouter(prefix="/api/v1/lnurl") withdraw_ext_lnurl.route_class = LNURLErrorResponseHandler ```
This commit is contained in:
+12
-2
@@ -8,11 +8,21 @@ from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.responses import JSONResponse, RedirectResponse, Response
|
||||
from loguru import logger
|
||||
|
||||
from lnbits.core.services import InvoiceError, PaymentError
|
||||
|
||||
from .helpers import template_renderer
|
||||
|
||||
|
||||
class PaymentError(Exception):
|
||||
def __init__(self, message: str, status: str = "pending"):
|
||||
self.message = message
|
||||
self.status = status
|
||||
|
||||
|
||||
class InvoiceError(Exception):
|
||||
def __init__(self, message: str, status: str = "pending"):
|
||||
self.message = message
|
||||
self.status = status
|
||||
|
||||
|
||||
def register_exception_handlers(app: FastAPI):
|
||||
register_exception_handler(app)
|
||||
register_request_validation_exception_handler(app)
|
||||
|
||||
Reference in New Issue
Block a user