MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / _parse_envelope

Function _parse_envelope

sdks/python/src/e2a/v1/errors.py:326–341  ·  view source on GitHub ↗
(data: Any, body: Any)

Source from the content-addressed store, hash-verified

324
325
326def _parse_envelope(data: Any, body: Any) -> Any:
327 # The generated layer may hand us a deserialized model, a dict, or a raw
328 # string body. Prefer a dict-shaped value; fall back to JSON-parsing body.
329 if isinstance(data, dict):
330 return data
331 if hasattr(data, "to_dict"):
332 try:
333 return data.to_dict()
334 except Exception: # pragma: no cover - defensive
335 pass
336 if isinstance(body, (str, bytes)):
337 try:
338 return json.loads(body)
339 except (ValueError, TypeError):
340 return None
341 return None
342
343
344def connection_error(message: str, cause: Optional[BaseException] = None) -> E2AConnectionError:

Callers 1

from_api_exceptionFunction · 0.85

Calls 1

to_dictMethod · 0.45

Tested by

no test coverage detected