From 1320ab03d87c4a75027bc4dfcc0eb08951ed6851 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Fri, 18 Jul 2025 15:32:28 +0200 Subject: Cloudflare impl --- cloudflare_api.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'cloudflare_api.py') 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 -- cgit v1.3.1