From 2cea15b78143ac64717a0105f689e76dce65d40d Mon Sep 17 00:00:00 2001 From: bromnhub <241785706+bromnhub@users.noreply.github.com> Date: Sun, 21 Dec 2025 05:01:57 -0500 Subject: [PATCH] refactor: Improve error handling in create_web_call function --- vapi_python/vapi_python.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vapi_python/vapi_python.py b/vapi_python/vapi_python.py index 69e9797..08a3e01 100644 --- a/vapi_python/vapi_python.py +++ b/vapi_python/vapi_python.py @@ -13,13 +13,16 @@ 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() 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']}") + # This case should ideally not be reached if raise_for_status() is used, + # but we keep it for safety if status code is not 201 but also not an error. + raise Exception(f"Error: Unexpected status code {response.status_code}") class Vapi: