From dd175a5802890a1f2e7f922dcf8db60cb6e6d086 Mon Sep 17 00:00:00 2001 From: Vivek Verma Date: Mon, 23 Mar 2026 19:40:26 +0530 Subject: [PATCH] Docs: add complete error handling example to quickstart --- docs/user/quickstart.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index cef9e088d8..8fae9a4fbb 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -568,6 +568,28 @@ If a request exceeds the configured number of maximum redirections, a All exceptions that Requests explicitly raises inherit from :exc:`requests.exceptions.RequestException`. +Complete Example with Error Handling +----------------------------------- + +Here is a complete example that demonstrates making a request and handling errors properly: + +.. code-block:: python + + import requests + from requests.exceptions import HTTPError + + url = "https://api.github.com" + + try: + response = requests.get(url) + response.raise_for_status() # Raises HTTPError for bad responses (4xx, 5xx) + except HTTPError as http_err: + print(f"HTTP error occurred: {http_err}") + except Exception as err: + print(f"Other error occurred: {err}") + else: + print("Success!") + print(response.text) ----------------------- Ready for more? Check out the :ref:`advanced ` section.