We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Docs incorrectly reference `HTTPError.message` attribute
### Checklist

<!-- Please make sure you check all these items before submitting your bug report. -->

- [x] The bug is reproducible against the latest release and/or `master`.
- [x] There are no similar issues or pull requests to fix it yet.

### Describe the bug

<!-- A clear and concise description of what the bug is. -->

The documentation indicates that message field can be used in the HTTPError:
https://github.com/encode/httpx/blob/master/httpx/_exceptions.py#L54
```
    try:
        response = httpx.get("https://www.example.com")
        response.raise_for_status()
    except httpx.HTTPError as exc:
        print(f"HTTP Exception for {exc.request.url} - {exc.message}")
```
But there is not such field:
```
AttributeError: 'HTTPStatusError' object has no attribute 'message'
```


### To reproduce

Execute the example from the doc

### Expected behavior

Print the string without raising any exceptions

### Actual behavior

AttributeError is raised

### Possible fixes

1. Update the documentation to use `str(exc)` instead of `exc.message`
or
2. Set `self.message` field in HTTPError


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `httpx/_exceptions.py`
Content:
```
1 """
2 Our exception hierarchy:
3 
4 * HTTPError
5   x RequestError
6     + TransportError
7       - TimeoutException
8         · ConnectTimeout
9         · ReadTimeout
10         · WriteTimeout
11         · PoolTimeout
12       - NetworkError
13         · ConnectError
14         · ReadError
15         · WriteError
16         · CloseError
17       - ProtocolError
18         · LocalProtocolError
19         · RemoteProtocolError
20       - ProxyError
21       - UnsupportedProtocol
22     + DecodingError
23     + TooManyRedirects
24     + RequestBodyUnavailable
25   x HTTPStatusError
26 * InvalidURL
27 * NotRedirectResponse
28 * CookieConflict
29 * StreamError
30   x StreamConsumed
31   x ResponseNotRead
32   x RequestNotRead
33   x ResponseClosed
34 """
35 import contextlib
36 import typing
37 
38 import httpcore
39 
40 if typing.TYPE_CHECKING:
41     from ._models import Request, Response  # pragma: nocover
42 
43 
44 class HTTPError(Exception):
45     """
46     Base class for `RequestError` and `HTTPStatusError`.
47 
48     Useful for `try...except` blocks when issuing a request,
49     and then calling `.raise_for_status()`.
50 
51     For example:
52 
53     ```
54     try:
55         response = httpx.get("https://www.example.com")
56         response.raise_for_status()
57     except httpx.HTTPError as exc:
58         print(f"HTTP Exception for {exc.request.url} - {exc.message}")
59     ```
60     """
61 
62     def __init__(self, message: str, *, request: "Request") -> None:
63         super().__init__(message)
64         self.request = request
65 
66 
67 class RequestError(HTTPError):
68     """
69     Base class for all exceptions that may occur when issuing a `.request()`.
70     """
71 
72     def __init__(self, message: str, *, request: "Request") -> None:
73         super().__init__(message, request=request)
74 
75 
76 class TransportError(RequestError):
77     """
78     Base class for all exceptions that occur at the level of the Transport API.
79 
80     All of these exceptions also have an equivelent mapping in `httpcore`.
81     """
82 
83 
84 # Timeout exceptions...
85 
86 
87 class TimeoutException(TransportError):
88     """
89     The base class for timeout errors.
90 
91     An operation has timed out.
92     """
93 
94 
95 class ConnectTimeout(TimeoutException):
96     """
97     Timed out while connecting to the host.
98     """
99 
100 
101 class ReadTimeout(TimeoutException):
102     """
103     Timed out while receiving data from the host.
104     """
105 
106 
107 class WriteTimeout(TimeoutException):
108     """
109     Timed out while sending data to the host.
110     """
111 
112 
113 class PoolTimeout(TimeoutException):
114     """
115     Timed out waiting to acquire a connection from the pool.
116     """
117 
118 
119 # Core networking exceptions...
120 
121 
122 class NetworkError(TransportError):
123     """
124     The base class for network-related errors.
125 
126     An error occurred while interacting with the network.
127     """
128 
129 
130 class ReadError(NetworkError):
131     """
132     Failed to receive data from the network.
133     """
134 
135 
136 class WriteError(NetworkError):
137     """
138     Failed to send data through the network.
139     """
140 
141 
142 class ConnectError(NetworkError):
143     """
144     Failed to establish a connection.
145     """
146 
147 
148 class CloseError(NetworkError):
149     """
150     Failed to close a connection.
151     """
152 
153 
154 # Other transport exceptions...
155 
156 
157 class ProxyError(TransportError):
158     """
159     An error occurred while establishing a proxy connection.
160     """
161 
162 
163 class UnsupportedProtocol(TransportError):
164     """
165     Attempted to make a request to an unsupported protocol.
166 
167     For example issuing a request to `ftp://www.example.com`.
168     """
169 
170 
171 class ProtocolError(TransportError):
172     """
173     The protocol was violated.
174     """
175 
176 
177 class LocalProtocolError(ProtocolError):
178     """
179     A protocol was violated by the client.
180 
181     For example if the user instantiated a `Request` instance explicitly,
182     failed to include the mandatory `Host:` header, and then issued it directly
183     using `client.send()`.
184     """
185 
186 
187 class RemoteProtocolError(ProtocolError):
188     """
189     The protocol was violated by the server.
190 
191     For exaample, returning malformed HTTP.
192     """
193 
194 
195 # Other request exceptions...
196 
197 
198 class DecodingError(RequestError):
199     """
200     Decoding of the response failed, due to a malformed encoding.
201     """
202 
203 
204 class TooManyRedirects(RequestError):
205     """
206     Too many redirects.
207     """
208 
209 
210 class RequestBodyUnavailable(RequestError):
211     """
212     Had to send the request again, but the request body was streaming, and is
213     no longer available.
214     """
215 
216 
217 # Client errors
218 
219 
220 class HTTPStatusError(HTTPError):
221     """
222     The response had an error HTTP status of 4xx or 5xx.
223 
224     May be raised when calling `response.raise_for_status()`
225     """
226 
227     def __init__(
228         self, message: str, *, request: "Request", response: "Response"
229     ) -> None:
230         super().__init__(message, request=request)
231         self.response = response
232 
233 
234 class InvalidURL(Exception):
235     """
236     URL is improperly formed or cannot be parsed.
237     """
238 
239     def __init__(self, message: str) -> None:
240         super().__init__(message)
241 
242 
243 class NotRedirectResponse(Exception):
244     """
245     Response was not a redirect response.
246 
247     May be raised if `response.next()` is called without first
248     properly checking `response.is_redirect`.
249     """
250 
251     def __init__(self, message: str) -> None:
252         super().__init__(message)
253 
254 
255 class CookieConflict(Exception):
256     """
257     Attempted to lookup a cookie by name, but multiple cookies existed.
258 
259     Can occur when calling `response.cookies.get(...)`.
260     """
261 
262     def __init__(self, message: str) -> None:
263         super().__init__(message)
264 
265 
266 # Stream exceptions...
267 
268 # These may occur as the result of a programming error, by accessing
269 # the request/response stream in an invalid manner.
270 
271 
272 class StreamError(Exception):
273     """
274     The base class for stream exceptions.
275 
276     The developer made an error in accessing the request stream in
277     an invalid way.
278     """
279 
280     def __init__(self, message: str) -> None:
281         super().__init__(message)
282 
283 
284 class StreamConsumed(StreamError):
285     """
286     Attempted to read or stream response content, but the content has already
287     been streamed.
288     """
289 
290     def __init__(self) -> None:
291         message = (
292             "Attempted to read or stream response content, but the content has "
293             "already been streamed."
294         )
295         super().__init__(message)
296 
297 
298 class ResponseNotRead(StreamError):
299     """
300     Attempted to access response content, without having called `read()`
301     after a streaming response.
302     """
303 
304     def __init__(self) -> None:
305         message = (
306             "Attempted to access response content, without having called `read()` "
307             "after a streaming response."
308         )
309         super().__init__(message)
310 
311 
312 class RequestNotRead(StreamError):
313     """
314     Attempted to access request content, without having called `read()`.
315     """
316 
317     def __init__(self) -> None:
318         message = "Attempted to access request content, without having called `read()`."
319         super().__init__(message)
320 
321 
322 class ResponseClosed(StreamError):
323     """
324     Attempted to read or stream response content, but the request has been
325     closed.
326     """
327 
328     def __init__(self) -> None:
329         message = (
330             "Attempted to read or stream response content, but the request has "
331             "been closed."
332         )
333         super().__init__(message)
334 
335 
336 @contextlib.contextmanager
337 def map_exceptions(
338     mapping: typing.Mapping[typing.Type[Exception], typing.Type[Exception]],
339     **kwargs: typing.Any,
340 ) -> typing.Iterator[None]:
341     try:
342         yield
343     except Exception as exc:
344         mapped_exc = None
345 
346         for from_exc, to_exc in mapping.items():
347             if not isinstance(exc, from_exc):
348                 continue
349             # We want to map to the most specific exception we can find.
350             # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to
351             # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.
352             if mapped_exc is None or issubclass(to_exc, mapped_exc):
353                 mapped_exc = to_exc
354 
355         if mapped_exc is None:
356             raise
357 
358         message = str(exc)
359         raise mapped_exc(message, **kwargs) from exc  # type: ignore
360 
361 
362 HTTPCORE_EXC_MAP = {
363     httpcore.TimeoutException: TimeoutException,
364     httpcore.ConnectTimeout: ConnectTimeout,
365     httpcore.ReadTimeout: ReadTimeout,
366     httpcore.WriteTimeout: WriteTimeout,
367     httpcore.PoolTimeout: PoolTimeout,
368     httpcore.NetworkError: NetworkError,
369     httpcore.ConnectError: ConnectError,
370     httpcore.ReadError: ReadError,
371     httpcore.WriteError: WriteError,
372     httpcore.CloseError: CloseError,
373     httpcore.ProxyError: ProxyError,
374     httpcore.UnsupportedProtocol: UnsupportedProtocol,
375     httpcore.ProtocolError: ProtocolError,
376     httpcore.LocalProtocolError: LocalProtocolError,
377     httpcore.RemoteProtocolError: RemoteProtocolError,
378 }
379
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/httpx/_exceptions.py b/httpx/_exceptions.py
--- a/httpx/_exceptions.py
+++ b/httpx/_exceptions.py
@@ -55,7 +55,7 @@
         response = httpx.get("https://www.example.com")
         response.raise_for_status()
     except httpx.HTTPError as exc:
-        print(f"HTTP Exception for {exc.request.url} - {exc.message}")
+        print(f"HTTP Exception for {exc.request.url} - {exc}")
     ```
     """

{"golden_diff": "diff --git a/httpx/_exceptions.py b/httpx/_exceptions.py\n--- a/httpx/_exceptions.py\n+++ b/httpx/_exceptions.py\n@@ -55,7 +55,7 @@\n         response = httpx.get(\"https://www.example.com\")\n         response.raise_for_status()\n     except httpx.HTTPError as exc:\n-        print(f\"HTTP Exception for {exc.request.url} - {exc.message}\")\n+        print(f\"HTTP Exception for {exc.request.url} - {exc}\")\n     ```\n     \"\"\"\n", "issue": "Docs incorrectly reference `HTTPError.message` attribute\n### Checklist\r\n\r\n<!-- Please make sure you check all these items before submitting your bug report. -->\r\n\r\n- [x] The bug is reproducible against the latest release and/or `master`.\r\n- [x] There are no similar issues or pull requests to fix it yet.\r\n\r\n### Describe the bug\r\n\r\n<!-- A clear and concise description of what the bug is. -->\r\n\r\nThe documentation indicates that message field can be used in the HTTPError:\r\nhttps://github.com/encode/httpx/blob/master/httpx/_exceptions.py#L54\r\n```\r\n    try:\r\n        response = httpx.get(\"https://www.example.com\")\r\n        response.raise_for_status()\r\n    except httpx.HTTPError as exc:\r\n        print(f\"HTTP Exception for {exc.request.url} - {exc.message}\")\r\n```\r\nBut there is not such field:\r\n```\r\nAttributeError: 'HTTPStatusError' object has no attribute 'message'\r\n```\r\n\r\n\r\n### To reproduce\r\n\r\nExecute the example from the doc\r\n\r\n### Expected behavior\r\n\r\nPrint the string without raising any exceptions\r\n\r\n### Actual behavior\r\n\r\nAttributeError is raised\r\n\r\n### Possible fixes\r\n\r\n1. Update the documentation to use `str(exc)` instead of `exc.message`\r\nor\r\n2. Set `self.message` field in HTTPError\r\n\n", "before_files": [{"content": "\"\"\"\nOur exception hierarchy:\n\n* HTTPError\n  x RequestError\n    + TransportError\n      - TimeoutException\n        \u00b7 ConnectTimeout\n        \u00b7 ReadTimeout\n        \u00b7 WriteTimeout\n        \u00b7 PoolTimeout\n      - NetworkError\n        \u00b7 ConnectError\n        \u00b7 ReadError\n        \u00b7 WriteError\n        \u00b7 CloseError\n      - ProtocolError\n        \u00b7 LocalProtocolError\n        \u00b7 RemoteProtocolError\n      - ProxyError\n      - UnsupportedProtocol\n    + DecodingError\n    + TooManyRedirects\n    + RequestBodyUnavailable\n  x HTTPStatusError\n* InvalidURL\n* NotRedirectResponse\n* CookieConflict\n* StreamError\n  x StreamConsumed\n  x ResponseNotRead\n  x RequestNotRead\n  x ResponseClosed\n\"\"\"\nimport contextlib\nimport typing\n\nimport httpcore\n\nif typing.TYPE_CHECKING:\n    from ._models import Request, Response  # pragma: nocover\n\n\nclass HTTPError(Exception):\n    \"\"\"\n    Base class for `RequestError` and `HTTPStatusError`.\n\n    Useful for `try...except` blocks when issuing a request,\n    and then calling `.raise_for_status()`.\n\n    For example:\n\n    ```\n    try:\n        response = httpx.get(\"https://www.example.com\")\n        response.raise_for_status()\n    except httpx.HTTPError as exc:\n        print(f\"HTTP Exception for {exc.request.url} - {exc.message}\")\n    ```\n    \"\"\"\n\n    def __init__(self, message: str, *, request: \"Request\") -> None:\n        super().__init__(message)\n        self.request = request\n\n\nclass RequestError(HTTPError):\n    \"\"\"\n    Base class for all exceptions that may occur when issuing a `.request()`.\n    \"\"\"\n\n    def __init__(self, message: str, *, request: \"Request\") -> None:\n        super().__init__(message, request=request)\n\n\nclass TransportError(RequestError):\n    \"\"\"\n    Base class for all exceptions that occur at the level of the Transport API.\n\n    All of these exceptions also have an equivelent mapping in `httpcore`.\n    \"\"\"\n\n\n# Timeout exceptions...\n\n\nclass TimeoutException(TransportError):\n    \"\"\"\n    The base class for timeout errors.\n\n    An operation has timed out.\n    \"\"\"\n\n\nclass ConnectTimeout(TimeoutException):\n    \"\"\"\n    Timed out while connecting to the host.\n    \"\"\"\n\n\nclass ReadTimeout(TimeoutException):\n    \"\"\"\n    Timed out while receiving data from the host.\n    \"\"\"\n\n\nclass WriteTimeout(TimeoutException):\n    \"\"\"\n    Timed out while sending data to the host.\n    \"\"\"\n\n\nclass PoolTimeout(TimeoutException):\n    \"\"\"\n    Timed out waiting to acquire a connection from the pool.\n    \"\"\"\n\n\n# Core networking exceptions...\n\n\nclass NetworkError(TransportError):\n    \"\"\"\n    The base class for network-related errors.\n\n    An error occurred while interacting with the network.\n    \"\"\"\n\n\nclass ReadError(NetworkError):\n    \"\"\"\n    Failed to receive data from the network.\n    \"\"\"\n\n\nclass WriteError(NetworkError):\n    \"\"\"\n    Failed to send data through the network.\n    \"\"\"\n\n\nclass ConnectError(NetworkError):\n    \"\"\"\n    Failed to establish a connection.\n    \"\"\"\n\n\nclass CloseError(NetworkError):\n    \"\"\"\n    Failed to close a connection.\n    \"\"\"\n\n\n# Other transport exceptions...\n\n\nclass ProxyError(TransportError):\n    \"\"\"\n    An error occurred while establishing a proxy connection.\n    \"\"\"\n\n\nclass UnsupportedProtocol(TransportError):\n    \"\"\"\n    Attempted to make a request to an unsupported protocol.\n\n    For example issuing a request to `ftp://www.example.com`.\n    \"\"\"\n\n\nclass ProtocolError(TransportError):\n    \"\"\"\n    The protocol was violated.\n    \"\"\"\n\n\nclass LocalProtocolError(ProtocolError):\n    \"\"\"\n    A protocol was violated by the client.\n\n    For example if the user instantiated a `Request` instance explicitly,\n    failed to include the mandatory `Host:` header, and then issued it directly\n    using `client.send()`.\n    \"\"\"\n\n\nclass RemoteProtocolError(ProtocolError):\n    \"\"\"\n    The protocol was violated by the server.\n\n    For exaample, returning malformed HTTP.\n    \"\"\"\n\n\n# Other request exceptions...\n\n\nclass DecodingError(RequestError):\n    \"\"\"\n    Decoding of the response failed, due to a malformed encoding.\n    \"\"\"\n\n\nclass TooManyRedirects(RequestError):\n    \"\"\"\n    Too many redirects.\n    \"\"\"\n\n\nclass RequestBodyUnavailable(RequestError):\n    \"\"\"\n    Had to send the request again, but the request body was streaming, and is\n    no longer available.\n    \"\"\"\n\n\n# Client errors\n\n\nclass HTTPStatusError(HTTPError):\n    \"\"\"\n    The response had an error HTTP status of 4xx or 5xx.\n\n    May be raised when calling `response.raise_for_status()`\n    \"\"\"\n\n    def __init__(\n        self, message: str, *, request: \"Request\", response: \"Response\"\n    ) -> None:\n        super().__init__(message, request=request)\n        self.response = response\n\n\nclass InvalidURL(Exception):\n    \"\"\"\n    URL is improperly formed or cannot be parsed.\n    \"\"\"\n\n    def __init__(self, message: str) -> None:\n        super().__init__(message)\n\n\nclass NotRedirectResponse(Exception):\n    \"\"\"\n    Response was not a redirect response.\n\n    May be raised if `response.next()` is called without first\n    properly checking `response.is_redirect`.\n    \"\"\"\n\n    def __init__(self, message: str) -> None:\n        super().__init__(message)\n\n\nclass CookieConflict(Exception):\n    \"\"\"\n    Attempted to lookup a cookie by name, but multiple cookies existed.\n\n    Can occur when calling `response.cookies.get(...)`.\n    \"\"\"\n\n    def __init__(self, message: str) -> None:\n        super().__init__(message)\n\n\n# Stream exceptions...\n\n# These may occur as the result of a programming error, by accessing\n# the request/response stream in an invalid manner.\n\n\nclass StreamError(Exception):\n    \"\"\"\n    The base class for stream exceptions.\n\n    The developer made an error in accessing the request stream in\n    an invalid way.\n    \"\"\"\n\n    def __init__(self, message: str) -> None:\n        super().__init__(message)\n\n\nclass StreamConsumed(StreamError):\n    \"\"\"\n    Attempted to read or stream response content, but the content has already\n    been streamed.\n    \"\"\"\n\n    def __init__(self) -> None:\n        message = (\n            \"Attempted to read or stream response content, but the content has \"\n            \"already been streamed.\"\n        )\n        super().__init__(message)\n\n\nclass ResponseNotRead(StreamError):\n    \"\"\"\n    Attempted to access response content, without having called `read()`\n    after a streaming response.\n    \"\"\"\n\n    def __init__(self) -> None:\n        message = (\n            \"Attempted to access response content, without having called `read()` \"\n            \"after a streaming response.\"\n        )\n        super().__init__(message)\n\n\nclass RequestNotRead(StreamError):\n    \"\"\"\n    Attempted to access request content, without having called `read()`.\n    \"\"\"\n\n    def __init__(self) -> None:\n        message = \"Attempted to access request content, without having called `read()`.\"\n        super().__init__(message)\n\n\nclass ResponseClosed(StreamError):\n    \"\"\"\n    Attempted to read or stream response content, but the request has been\n    closed.\n    \"\"\"\n\n    def __init__(self) -> None:\n        message = (\n            \"Attempted to read or stream response content, but the request has \"\n            \"been closed.\"\n        )\n        super().__init__(message)\n\n\n@contextlib.contextmanager\ndef map_exceptions(\n    mapping: typing.Mapping[typing.Type[Exception], typing.Type[Exception]],\n    **kwargs: typing.Any,\n) -> typing.Iterator[None]:\n    try:\n        yield\n    except Exception as exc:\n        mapped_exc = None\n\n        for from_exc, to_exc in mapping.items():\n            if not isinstance(exc, from_exc):\n                continue\n            # We want to map to the most specific exception we can find.\n            # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to\n            # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.\n            if mapped_exc is None or issubclass(to_exc, mapped_exc):\n                mapped_exc = to_exc\n\n        if mapped_exc is None:\n            raise\n\n        message = str(exc)\n        raise mapped_exc(message, **kwargs) from exc  # type: ignore\n\n\nHTTPCORE_EXC_MAP = {\n    httpcore.TimeoutException: TimeoutException,\n    httpcore.ConnectTimeout: ConnectTimeout,\n    httpcore.ReadTimeout: ReadTimeout,\n    httpcore.WriteTimeout: WriteTimeout,\n    httpcore.PoolTimeout: PoolTimeout,\n    httpcore.NetworkError: NetworkError,\n    httpcore.ConnectError: ConnectError,\n    httpcore.ReadError: ReadError,\n    httpcore.WriteError: WriteError,\n    httpcore.CloseError: CloseError,\n    httpcore.ProxyError: ProxyError,\n    httpcore.UnsupportedProtocol: UnsupportedProtocol,\n    httpcore.ProtocolError: ProtocolError,\n    httpcore.LocalProtocolError: LocalProtocolError,\n    httpcore.RemoteProtocolError: RemoteProtocolError,\n}\n", "path": "httpx/_exceptions.py"}], "after_files": [{"content": "\"\"\"\nOur exception hierarchy:\n\n* HTTPError\n  x RequestError\n    + TransportError\n      - TimeoutException\n        \u00b7 ConnectTimeout\n        \u00b7 ReadTimeout\n        \u00b7 WriteTimeout\n        \u00b7 PoolTimeout\n      - NetworkError\n        \u00b7 ConnectError\n        \u00b7 ReadError\n        \u00b7 WriteError\n        \u00b7 CloseError\n      - ProtocolError\n        \u00b7 LocalProtocolError\n        \u00b7 RemoteProtocolError\n      - ProxyError\n      - UnsupportedProtocol\n    + DecodingError\n    + TooManyRedirects\n    + RequestBodyUnavailable\n  x HTTPStatusError\n* InvalidURL\n* NotRedirectResponse\n* CookieConflict\n* StreamError\n  x StreamConsumed\n  x ResponseNotRead\n  x RequestNotRead\n  x ResponseClosed\n\"\"\"\nimport contextlib\nimport typing\n\nimport httpcore\n\nif typing.TYPE_CHECKING:\n    from ._models import Request, Response  # pragma: nocover\n\n\nclass HTTPError(Exception):\n    \"\"\"\n    Base class for `RequestError` and `HTTPStatusError`.\n\n    Useful for `try...except` blocks when issuing a request,\n    and then calling `.raise_for_status()`.\n\n    For example:\n\n    ```\n    try:\n        response = httpx.get(\"https://www.example.com\")\n        response.raise_for_status()\n    except httpx.HTTPError as exc:\n        print(f\"HTTP Exception for {exc.request.url} - {exc}\")\n    ```\n    \"\"\"\n\n    def __init__(self, message: str, *, request: \"Request\") -> None:\n        super().__init__(message)\n        self.request = request\n\n\nclass RequestError(HTTPError):\n    \"\"\"\n    Base class for all exceptions that may occur when issuing a `.request()`.\n    \"\"\"\n\n    def __init__(self, message: str, *, request: \"Request\") -> None:\n        super().__init__(message, request=request)\n\n\nclass TransportError(RequestError):\n    \"\"\"\n    Base class for all exceptions that occur at the level of the Transport API.\n\n    All of these exceptions also have an equivelent mapping in `httpcore`.\n    \"\"\"\n\n\n# Timeout exceptions...\n\n\nclass TimeoutException(TransportError):\n    \"\"\"\n    The base class for timeout errors.\n\n    An operation has timed out.\n    \"\"\"\n\n\nclass ConnectTimeout(TimeoutException):\n    \"\"\"\n    Timed out while connecting to the host.\n    \"\"\"\n\n\nclass ReadTimeout(TimeoutException):\n    \"\"\"\n    Timed out while receiving data from the host.\n    \"\"\"\n\n\nclass WriteTimeout(TimeoutException):\n    \"\"\"\n    Timed out while sending data to the host.\n    \"\"\"\n\n\nclass PoolTimeout(TimeoutException):\n    \"\"\"\n    Timed out waiting to acquire a connection from the pool.\n    \"\"\"\n\n\n# Core networking exceptions...\n\n\nclass NetworkError(TransportError):\n    \"\"\"\n    The base class for network-related errors.\n\n    An error occurred while interacting with the network.\n    \"\"\"\n\n\nclass ReadError(NetworkError):\n    \"\"\"\n    Failed to receive data from the network.\n    \"\"\"\n\n\nclass WriteError(NetworkError):\n    \"\"\"\n    Failed to send data through the network.\n    \"\"\"\n\n\nclass ConnectError(NetworkError):\n    \"\"\"\n    Failed to establish a connection.\n    \"\"\"\n\n\nclass CloseError(NetworkError):\n    \"\"\"\n    Failed to close a connection.\n    \"\"\"\n\n\n# Other transport exceptions...\n\n\nclass ProxyError(TransportError):\n    \"\"\"\n    An error occurred while establishing a proxy connection.\n    \"\"\"\n\n\nclass UnsupportedProtocol(TransportError):\n    \"\"\"\n    Attempted to make a request to an unsupported protocol.\n\n    For example issuing a request to `ftp://www.example.com`.\n    \"\"\"\n\n\nclass ProtocolError(TransportError):\n    \"\"\"\n    The protocol was violated.\n    \"\"\"\n\n\nclass LocalProtocolError(ProtocolError):\n    \"\"\"\n    A protocol was violated by the client.\n\n    For example if the user instantiated a `Request` instance explicitly,\n    failed to include the mandatory `Host:` header, and then issued it directly\n    using `client.send()`.\n    \"\"\"\n\n\nclass RemoteProtocolError(ProtocolError):\n    \"\"\"\n    The protocol was violated by the server.\n\n    For exaample, returning malformed HTTP.\n    \"\"\"\n\n\n# Other request exceptions...\n\n\nclass DecodingError(RequestError):\n    \"\"\"\n    Decoding of the response failed, due to a malformed encoding.\n    \"\"\"\n\n\nclass TooManyRedirects(RequestError):\n    \"\"\"\n    Too many redirects.\n    \"\"\"\n\n\nclass RequestBodyUnavailable(RequestError):\n    \"\"\"\n    Had to send the request again, but the request body was streaming, and is\n    no longer available.\n    \"\"\"\n\n\n# Client errors\n\n\nclass HTTPStatusError(HTTPError):\n    \"\"\"\n    The response had an error HTTP status of 4xx or 5xx.\n\n    May be raised when calling `response.raise_for_status()`\n    \"\"\"\n\n    def __init__(\n        self, message: str, *, request: \"Request\", response: \"Response\"\n    ) -> None:\n        super().__init__(message, request=request)\n        self.response = response\n\n\nclass InvalidURL(Exception):\n    \"\"\"\n    URL is improperly formed or cannot be parsed.\n    \"\"\"\n\n    def __init__(self, message: str) -> None:\n        super().__init__(message)\n\n\nclass NotRedirectResponse(Exception):\n    \"\"\"\n    Response was not a redirect response.\n\n    May be raised if `response.next()` is called without first\n    properly checking `response.is_redirect`.\n    \"\"\"\n\n    def __init__(self, message: str) -> None:\n        super().__init__(message)\n\n\nclass CookieConflict(Exception):\n    \"\"\"\n    Attempted to lookup a cookie by name, but multiple cookies existed.\n\n    Can occur when calling `response.cookies.get(...)`.\n    \"\"\"\n\n    def __init__(self, message: str) -> None:\n        super().__init__(message)\n\n\n# Stream exceptions...\n\n# These may occur as the result of a programming error, by accessing\n# the request/response stream in an invalid manner.\n\n\nclass StreamError(Exception):\n    \"\"\"\n    The base class for stream exceptions.\n\n    The developer made an error in accessing the request stream in\n    an invalid way.\n    \"\"\"\n\n    def __init__(self, message: str) -> None:\n        super().__init__(message)\n\n\nclass StreamConsumed(StreamError):\n    \"\"\"\n    Attempted to read or stream response content, but the content has already\n    been streamed.\n    \"\"\"\n\n    def __init__(self) -> None:\n        message = (\n            \"Attempted to read or stream response content, but the content has \"\n            \"already been streamed.\"\n        )\n        super().__init__(message)\n\n\nclass ResponseNotRead(StreamError):\n    \"\"\"\n    Attempted to access response content, without having called `read()`\n    after a streaming response.\n    \"\"\"\n\n    def __init__(self) -> None:\n        message = (\n            \"Attempted to access response content, without having called `read()` \"\n            \"after a streaming response.\"\n        )\n        super().__init__(message)\n\n\nclass RequestNotRead(StreamError):\n    \"\"\"\n    Attempted to access request content, without having called `read()`.\n    \"\"\"\n\n    def __init__(self) -> None:\n        message = \"Attempted to access request content, without having called `read()`.\"\n        super().__init__(message)\n\n\nclass ResponseClosed(StreamError):\n    \"\"\"\n    Attempted to read or stream response content, but the request has been\n    closed.\n    \"\"\"\n\n    def __init__(self) -> None:\n        message = (\n            \"Attempted to read or stream response content, but the request has \"\n            \"been closed.\"\n        )\n        super().__init__(message)\n\n\n@contextlib.contextmanager\ndef map_exceptions(\n    mapping: typing.Mapping[typing.Type[Exception], typing.Type[Exception]],\n    **kwargs: typing.Any,\n) -> typing.Iterator[None]:\n    try:\n        yield\n    except Exception as exc:\n        mapped_exc = None\n\n        for from_exc, to_exc in mapping.items():\n            if not isinstance(exc, from_exc):\n                continue\n            # We want to map to the most specific exception we can find.\n            # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to\n            # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.\n            if mapped_exc is None or issubclass(to_exc, mapped_exc):\n                mapped_exc = to_exc\n\n        if mapped_exc is None:\n            raise\n\n        message = str(exc)\n        raise mapped_exc(message, **kwargs) from exc  # type: ignore\n\n\nHTTPCORE_EXC_MAP = {\n    httpcore.TimeoutException: TimeoutException,\n    httpcore.ConnectTimeout: ConnectTimeout,\n    httpcore.ReadTimeout: ReadTimeout,\n    httpcore.WriteTimeout: WriteTimeout,\n    httpcore.PoolTimeout: PoolTimeout,\n    httpcore.NetworkError: NetworkError,\n    httpcore.ConnectError: ConnectError,\n    httpcore.ReadError: ReadError,\n    httpcore.WriteError: WriteError,\n    httpcore.CloseError: CloseError,\n    httpcore.ProxyError: ProxyError,\n    httpcore.UnsupportedProtocol: UnsupportedProtocol,\n    httpcore.ProtocolError: ProtocolError,\n    httpcore.LocalProtocolError: LocalProtocolError,\n    httpcore.RemoteProtocolError: RemoteProtocolError,\n}\n", "path": "httpx/_exceptions.py"}]}