in client/json_rpc.py [0:0]
def from_json(response_json: JSON) -> "ErrorResponse":
"""
Parse a given JSON into a JSON-RPC error response.
Raises `InvalidRequestError` if the JSON body is malformed.
"""
_verify_json_rpc_version(response_json)
error = response_json.get("error")
if error is None:
raise InvalidRequestError(
f"Required field `error` is missing: {response_json}"
)
if not isinstance(error, dict):
raise InvalidRequestError(f"`error` must be a dict but got {error}")
code = error.get("code")
if code is None:
raise InvalidRequestError(
f"Required field `error.code` is missing: {response_json}"
)
if not isinstance(code, int):
raise InvalidRequestError(
f"`error.code` is expected to be an int but got {code}"
)
message = error.get("message", "")
if not isinstance(message, str):
raise InvalidRequestError(
f"`error.message` is expected to be a string but got {message}"
)
data = error.get("data")
# FIXME: The `id` field is required for the respnose, but we can't
# enforce it right now since the Pyre server may emit id-less responses
# and that has to be fixed first.
id = _parse_json_rpc_id(response_json)
return ErrorResponse(id=id, code=code, message=message, data=data)