From f75626e884a80f5c269dffe041099485eec0465e Mon Sep 17 00:00:00 2001 From: bromnhub <241785706+bromnhub@users.noreply.github.com> Date: Mon, 22 Dec 2025 05:03:23 -0500 Subject: [PATCH] refactor: Improve HTTP error handling in create_web_call --- vapi_python/vapi_python.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vapi_python/vapi_python.py b/vapi_python/vapi_python.py index 69e9797..afc0570 100644 --- a/vapi_python/vapi_python.py +++ b/vapi_python/vapi_python.py @@ -13,13 +13,17 @@ def create_web_call(api_url, api_key, payload): 'Content-Type': 'application/json' } response = requests.post(url, headers=headers, json=payload) + response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx) + data = response.json() if response.status_code == 201: call_id = data.get('id') web_call_url = data.get('webCallUrl') return call_id, web_call_url - else: - raise Exception(f"Error: {data['message']}") + + # If we reach here, the status code was 2xx but not 201, which is unexpected for a creation endpoint. + # We raise an exception to be safe, though raise_for_status() handles 4xx/5xx. + raise Exception(f"Unexpected successful status code {response.status_code}. Response: {data}") class Vapi: