blitz_api/app/lightning/utils.py
fusion44 e290de8933
feat: proper error handling resolving peer aliases
Implementations sometimes don't find aliases in the gossip, even if
they are openeing a channel to the pubkey. In this case an empty
string will be returned and the problem logged in debug mode.

refs #199
2023-05-01 20:48:10 +02:00

31 lines
763 B
Python

import grpc
from fastapi import HTTPException
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(f"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 ""