chore: use HTTPStatus where possible (#2795)
This commit is contained in:
parent
fa71219ce7
commit
5104cbb285
3 changed files with 15 additions and 8 deletions
|
|
@ -69,7 +69,7 @@ public_node_router = APIRouter(
|
||||||
@node_router.get(
|
@node_router.get(
|
||||||
"/ok",
|
"/ok",
|
||||||
description="Check if node api can be enabled",
|
description="Check if node api can be enabled",
|
||||||
status_code=200,
|
status_code=HTTPStatus.OK,
|
||||||
dependencies=[Depends(require_node)],
|
dependencies=[Depends(require_node)],
|
||||||
)
|
)
|
||||||
async def api_get_ok():
|
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"]
|
return r.json()["noderank"]
|
||||||
except httpx.HTTPStatusError as exc:
|
except httpx.HTTPStatusError as exc:
|
||||||
raise HTTPException(
|
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
|
) from exc
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
from http import HTTPStatus
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
from fastapi import HTTPException, Request, Response
|
from fastapi import HTTPException, Request, Response
|
||||||
|
|
@ -31,21 +32,21 @@ class LnurlErrorResponseHandler(APIRoute):
|
||||||
except (InvoiceError, PaymentError) as exc:
|
except (InvoiceError, PaymentError) as exc:
|
||||||
logger.debug(f"Wallet Error: {exc}")
|
logger.debug(f"Wallet Error: {exc}")
|
||||||
response = JSONResponse(
|
response = JSONResponse(
|
||||||
status_code=200,
|
status_code=HTTPStatus.OK,
|
||||||
content={"status": "ERROR", "reason": f"{exc.message}"},
|
content={"status": "ERROR", "reason": f"{exc.message}"},
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
except HTTPException as exc:
|
except HTTPException as exc:
|
||||||
logger.debug(f"HTTPException: {exc}")
|
logger.debug(f"HTTPException: {exc}")
|
||||||
response = JSONResponse(
|
response = JSONResponse(
|
||||||
status_code=200,
|
status_code=HTTPStatus.OK,
|
||||||
content={"status": "ERROR", "reason": f"{exc.detail}"},
|
content={"status": "ERROR", "reason": f"{exc.detail}"},
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error("Unknown Error:", exc)
|
logger.error("Unknown Error:", exc)
|
||||||
response = JSONResponse(
|
response = JSONResponse(
|
||||||
status_code=200,
|
status_code=HTTPStatus.OK,
|
||||||
content={
|
content={
|
||||||
"status": "ERROR",
|
"status": "ERROR",
|
||||||
"reason": f"UNKNOWN ERROR: {exc!s}",
|
"reason": f"UNKNOWN ERROR: {exc!s}",
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,13 @@ def catch_rpc_errors(f):
|
||||||
except RpcError as exc:
|
except RpcError as exc:
|
||||||
msg = exc.error["message"]
|
msg = exc.error["message"]
|
||||||
if exc.error["code"] == -32602:
|
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:
|
else:
|
||||||
raise HTTPException(status_code=500, detail=msg) from exc
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=msg
|
||||||
|
) from exc
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
@ -152,7 +156,9 @@ class CoreLightningNode(Node):
|
||||||
force: bool = False,
|
force: bool = False,
|
||||||
):
|
):
|
||||||
if not short_id:
|
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:
|
try:
|
||||||
await self.ln_rpc("close", short_id)
|
await self.ln_rpc("close", short_id)
|
||||||
except RpcError as exc:
|
except RpcError as exc:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue