mirror of
https://github.com/fusion44/blitz_api.git
synced 2026-08-13 11:52:45 +02:00
31 lines
770 B
Python
31 lines
770 B
Python
import grpc
|
|
from fastapi import HTTPException, status
|
|
from loguru import logger
|
|
|
|
from app.lightning.exceptions import NodeNotFoundError
|
|
|
|
|
|
def generic_grpc_error_handler(error: grpc.aio._call.AioRpcError):
|
|
details = error.details()
|
|
logger.debug(details)
|
|
|
|
raise HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR, detail=details)
|
|
|
|
|
|
async def alias_or_empty(func, node_pub: str) -> str:
|
|
logger.debug(f"alias_or_empty({node_pub})")
|
|
|
|
if not node_pub:
|
|
logger.debug("alias_or_empty('') -> ''")
|
|
|
|
return ""
|
|
|
|
try:
|
|
res = await func(node_pub)
|
|
logger.debug(f"alias_or_empty -> {node_pub}")
|
|
|
|
return res
|
|
except NodeNotFoundError:
|
|
logger.debug(f"NodeNotFoundError for node_pub={node_pub}")
|
|
|
|
return ""
|