Skip to content
Myr

Rework docs structure (#2308)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Florimond Manca · committed by GitHub · parent 3aa4410 · Browse files · 3 files+74 added−62 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+74 added−62 removed

  • other:+74 added−62 removed

3 files+74 added−62 removed

modified:docs/exceptions.md+2 added-50 removed
modified:docs/quickstart.md+54 added
477 unmodified lines
478>>> auth = httpx.DigestAuth("my_user", "password123")479>>> httpx.get("https://example.com", auth=auth)480<Response [200 OK]>481```482483## Exceptions484485HTTPX will raise exceptions if an error occurs.486487The most important exception classes in HTTPX are `RequestError` and `HTTPStatusError`.488489The `RequestError` class is a superclass that encompasses any exception that occurs490while issuing an HTTP request. These exceptions include a `.request` attribute.491492```python493try:494 response = httpx.get("https://www.example.com/")495except httpx.RequestError as exc:496 print(f"An error occurred while requesting {exc.request.url!r}.")497```498499The `HTTPStatusError` class is raised by `response.raise_for_status()` on responses which are not a 2xx success code.500These exceptions include both a `.request` and a `.response` attribute.501502```python503response = httpx.get("https://www.example.com/")504try:505 response.raise_for_status()506except httpx.HTTPStatusError as exc:507 print(f"Error response {exc.response.status_code} while requesting {exc.request.url!r}.")508```509510There is also a base class `HTTPError` that includes both of these categories, and can be used511to catch either failed requests, or 4xx and 5xx responses.512513You can either use this base class to catch both categories...514515```python516try:517 response = httpx.get("https://www.example.com/")518 response.raise_for_status()519except httpx.HTTPError as exc:520 print(f"Error while requesting {exc.request.url!r}.")521```522523Or handle each case explicitly...524525```python526try:527 response = httpx.get("https://www.example.com/")528 response.raise_for_status()529except httpx.RequestError as exc:530 print(f"An error occurred while requesting {exc.request.url!r}.")531except httpx.HTTPStatusError as exc:532 print(f"Error response {exc.response.status_code} while requesting {exc.request.url!r}.")533```534535For a full list of available exceptions, see [Exceptions (API Reference)](exceptions.md).
modified:mkdocs.yml+18 added-12 removed