mirror of
https://github.com/lnbits/lnbits.git
synced 2025-03-17 21:31:55 +01:00
chore: use HTTPStatus where possible (#2795)
This commit is contained in:
parent
fa71219ce7
commit
5104cbb285
@ -69,7 +69,7 @@ public_node_router = APIRouter(
|
||||
@node_router.get(
|
||||
"/ok",
|
||||
description="Check if node api can be enabled",
|
||||
status_code=200,
|
||||
status_code=HTTPStatus.OK,
|
||||
dependencies=[Depends(require_node)],
|
||||
)
|
||||
async def api_get_ok():
|
||||
@ -197,5 +197,5 @@ async def api_get_1ml_stats(node: Node = Depends(require_node)) -> Optional[Node
|
||||
return r.json()["noderank"]
|
||||
except httpx.HTTPStatusError as exc:
|
||||
raise HTTPException(
|
||||
status_code=404, detail="Node not found on 1ml.com"
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Node not found on 1ml.com"
|
||||
) from exc
|
||||
|
@ -1,3 +1,4 @@
|
||||
from http import HTTPStatus
|
||||
from typing import Callable
|
||||
|
||||
from fastapi import HTTPException, Request, Response
|
||||
@ -31,21 +32,21 @@ class LnurlErrorResponseHandler(APIRoute):
|
||||
except (InvoiceError, PaymentError) as exc:
|
||||
logger.debug(f"Wallet Error: {exc}")
|
||||
response = JSONResponse(
|
||||
status_code=200,
|
||||
status_code=HTTPStatus.OK,
|
||||
content={"status": "ERROR", "reason": f"{exc.message}"},
|
||||
)
|
||||
return response
|
||||
except HTTPException as exc:
|
||||
logger.debug(f"HTTPException: {exc}")
|
||||
response = JSONResponse(
|
||||
status_code=200,
|
||||
status_code=HTTPStatus.OK,
|
||||
content={"status": "ERROR", "reason": f"{exc.detail}"},
|
||||
)
|
||||
return response
|
||||
except Exception as exc:
|
||||
logger.error("Unknown Error:", exc)
|
||||
response = JSONResponse(
|
||||
status_code=200,
|
||||
status_code=HTTPStatus.OK,
|
||||
content={
|
||||
"status": "ERROR",
|
||||
"reason": f"UNKNOWN ERROR: {exc!s}",
|
||||
|
@ -47,9 +47,13 @@ def catch_rpc_errors(f):
|
||||
except RpcError as exc:
|
||||
msg = exc.error["message"]
|
||||
if exc.error["code"] == -32602:
|
||||
raise HTTPException(status_code=400, detail=msg) from exc
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST, detail=msg
|
||||
) from exc
|
||||
else:
|
||||
raise HTTPException(status_code=500, detail=msg) from exc
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=msg
|
||||
) from exc
|
||||
|
||||
return wrapper
|
||||
|
||||
@ -152,7 +156,9 @@ class CoreLightningNode(Node):
|
||||
force: bool = False,
|
||||
):
|
||||
if not short_id:
|
||||
raise HTTPException(status_code=400, detail="Short id required")
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST, detail="Short id required"
|
||||
)
|
||||
try:
|
||||
await self.ln_rpc("close", short_id)
|
||||
except RpcError as exc:
|
||||
|
Loading…
x
Reference in New Issue
Block a user