summaryrefslogtreecommitdiff
path: root/cloudflare_api.py
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2025-07-18 15:32:28 +0200
committerYuval Adam <_@yuv.al>2025-07-18 15:32:28 +0200
commit1320ab03d87c4a75027bc4dfcc0eb08951ed6851 (patch)
treedd888baafde419b98db31dc0bd462a1bf622fe35 /cloudflare_api.py
parentdb420dc6a075d23e1aa3ef45fb9cf6b286096c1b (diff)
Cloudflare impl
Diffstat (limited to 'cloudflare_api.py')
-rw-r--r--cloudflare_api.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/cloudflare_api.py b/cloudflare_api.py
index 745f763..16fd926 100644
--- a/cloudflare_api.py
+++ b/cloudflare_api.py
@@ -16,14 +16,31 @@ class CloudflareAPI:
url = f"{self.base_url}{endpoint}"
response = requests.request(method, url, headers=self.headers, json=data, timeout=30)
- response.raise_for_status()
+
+ try:
+ response.raise_for_status()
+ except requests.exceptions.HTTPError as e:
+ # Try to get the error details from the response
+ try:
+ error_details = response.json()
+ errors = error_details.get('errors', [])
+ if errors:
+ error_msg = ', '.join([error.get('message', 'Unknown error') for error in errors])
+ raise Exception(f"Cloudflare API Error: {error_msg}")
+ else:
+ raise Exception(f"Cloudflare API Error: {response.status_code} - {response.text}")
+ except ValueError:
+ raise Exception(f"Cloudflare API Error: {response.status_code} - {response.text}")
result = response.json()
if not result.get('success', False):
errors = result.get('errors', [])
- error_msg = ', '.join([error.get('message', 'Unknown error') for error in errors])
- raise Exception(f"Cloudflare API Error: {error_msg}")
+ if errors:
+ error_msg = ', '.join([error.get('message', 'Unknown error') for error in errors])
+ raise Exception(f"Cloudflare API Error: {error_msg}")
+ else:
+ raise Exception(f"Cloudflare API Error: Request failed but no error details provided")
return result