MCPcopy
hub / github.com/encode/httpx / map_httpcore_exceptions

Function map_httpcore_exceptions

httpx/_transports/default.py:96–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

94
95@contextlib.contextmanager
96def map_httpcore_exceptions() -> typing.Iterator[None]:
97 global HTTPCORE_EXC_MAP
98 if len(HTTPCORE_EXC_MAP) == 0:
99 HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
100 try:
101 yield
102 except Exception as exc:
103 mapped_exc = None
104
105 for from_exc, to_exc in HTTPCORE_EXC_MAP.items():
106 if not isinstance(exc, from_exc):
107 continue
108 # We want to map to the most specific exception we can find.
109 # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to
110 # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.
111 if mapped_exc is None or issubclass(to_exc, mapped_exc):
112 mapped_exc = to_exc
113
114 if mapped_exc is None: # pragma: no cover
115 raise
116
117 message = str(exc)
118 raise mapped_exc(message) from exc
119
120
121class ResponseStream(SyncByteStream):

Callers 6

__iter__Method · 0.85
__exit__Method · 0.85
handle_requestMethod · 0.85
__aiter__Method · 0.85
__aexit__Method · 0.85
handle_async_requestMethod · 0.85

Calls 2

itemsMethod · 0.45

Tested by

no test coverage detected