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

Function from_api_exception

sdks/python/src/e2a/v1/errors.py:282–308  ·  view source on GitHub ↗

Map a generated ``ApiException`` (raised by the generated ``*Api`` classes on a non-2xx response) to a typed :class:`E2AError`.

(exc: ApiException)

Source from the content-addressed store, hash-verified

280
281
282def from_api_exception(exc: ApiException) -> E2AError:
283 """Map a generated ``ApiException`` (raised by the generated ``*Api`` classes on a
284 non-2xx response) to a typed :class:`E2AError`."""
285 headers = _normalize_headers(getattr(exc, "headers", None))
286 request_id = _header_get(headers, "x-request-id")
287 status = int(getattr(exc, "status", 0) or 0)
288
289 code = ""
290 message = getattr(exc, "reason", None) or str(exc)
291 details: Any = None
292 env = _parse_envelope(getattr(exc, "data", None), getattr(exc, "body", None))
293 if isinstance(env, dict):
294 error = env.get("error")
295 if isinstance(error, dict):
296 code = error.get("code") or ""
297 message = error.get("message") or message
298 details = error.get("details")
299
300 return to_e2a_error(
301 status=status,
302 code=code,
303 message=message,
304 request_id=request_id,
305 details=details,
306 headers=headers,
307 cause=exc,
308 )
309
310
311def _normalize_headers(headers: Any) -> Optional[Mapping[str, str]]:

Calls 5

_normalize_headersFunction · 0.85
_header_getFunction · 0.85
_parse_envelopeFunction · 0.85
to_e2a_errorFunction · 0.85
getMethod · 0.45