From 132006a78609308bdc6800917bdedf182670d59a Mon Sep 17 00:00:00 2001 From: Kavya Dave Date: Thu, 23 Oct 2025 15:53:37 +0530 Subject: [PATCH] Add documentation on surfacing error codes (#231) --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 22049d46..453cdf1b 100644 --- a/README.md +++ b/README.md @@ -283,3 +283,23 @@ Long term: - The client currently inputs and outputs JSON dictionaries. Adding models would unlock features such as typing and validation. - Add supporting functions to elevate customer experience (i.e. adding a funtion that surfaces IP address for a Droplet) + +- Add supporting functions to elevate customer experience (i.e. adding a funtion that surfaces IP address for a Droplet) + +### 🧩 Handling Error Codes + +When using `pydo`, some API responses may include specific error codes. +To make debugging easier, you can catch and print these codes from exceptions. + +**Example:** +```python +from pydo import Client +import os + +client = Client(token=os.getenv("DIGITALOCEAN_TOKEN")) + +try: + client.droplets.list() +except Exception as e: + print("Error code:", getattr(e, "code", "Unknown")) + print("Error message:", e)