Part of https://www.notion.so/Laconic-Mainnet-Plan-1eca6b22d47280569cd0d1e6d711d949 Co-authored-by: Shreerang Kale <shreerangkale@gmail.com> Reviewed-on: #1 Co-authored-by: shreerang <shreerang@noreply.git.vdb.to> Co-committed-by: shreerang <shreerang@noreply.git.vdb.to>
29 lines
759 B
Python
29 lines
759 B
Python
from typing import Dict, Any
|
|
|
|
|
|
def normalize_response(provider: str, response: Dict[str, Any]) -> Dict[str, Any]:
|
|
normalized = response.copy()
|
|
|
|
# Ensure consistent field names
|
|
if "result" in normalized and normalized["result"] is None:
|
|
# Some providers return null, others omit the field
|
|
pass
|
|
|
|
# Handle null vs missing fields consistently
|
|
if "error" in normalized and normalized["error"] is None:
|
|
del normalized["error"]
|
|
|
|
return normalized
|
|
|
|
|
|
def normalize_error(error: Exception, error_id: str) -> Dict[str, Any]:
|
|
return {
|
|
"jsonrpc": "2.0",
|
|
"id": 1,
|
|
"error": {
|
|
"code": -32603,
|
|
"message": str(error),
|
|
"data": {"error_id": error_id}
|
|
}
|
|
}
|