mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-10-27 04:55:25 +03:00
584000f0b3
* rpc: Move `RPCServer._wrap_http_handler` to `chia.rpc.util` * rpc: Introduce `RPCServer.get_routes` * rpc|tests: Introduce RPC endpoint `/get_routes`
32 lines
898 B
Python
32 lines
898 B
Python
import logging
|
|
import traceback
|
|
from typing import Callable
|
|
|
|
import aiohttp
|
|
|
|
from chia.util.json_util import obj_to_response
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
def wrap_http_handler(f) -> Callable:
|
|
async def inner(request) -> aiohttp.web.Response:
|
|
request_data = await request.json()
|
|
try:
|
|
res_object = await f(request_data)
|
|
if res_object is None:
|
|
res_object = {}
|
|
if "success" not in res_object:
|
|
res_object["success"] = True
|
|
except Exception as e:
|
|
tb = traceback.format_exc()
|
|
log.warning(f"Error while handling message: {tb}")
|
|
if len(e.args) > 0:
|
|
res_object = {"success": False, "error": f"{e.args[0]}"}
|
|
else:
|
|
res_object = {"success": False, "error": f"{e}"}
|
|
|
|
return obj_to_response(res_object)
|
|
|
|
return inner
|