From dd217bbb0c3d609fd0aa4e8f209a760790294448 Mon Sep 17 00:00:00 2001 From: bromnhub <241785706+bromnhub@users.noreply.github.com> Date: Mon, 8 Dec 2025 05:02:54 -0500 Subject: [PATCH] refactor: Improve error handling in create_web_call with requests.raise_for_status --- vapi_python/vapi_python.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vapi_python/vapi_python.py b/vapi_python/vapi_python.py index 69e9797..907518f 100644 --- a/vapi_python/vapi_python.py +++ b/vapi_python/vapi_python.py @@ -14,12 +14,14 @@ def create_web_call(api_url, api_key, payload): } response = requests.post(url, headers=headers, json=payload) data = response.json() + # We call response.json() before raise_for_status() to ensure we have the error message + # in 'data' in case of an exception, although raise_for_status() will handle the HTTP error. + response.raise_for_status() + # The API returns 201 on success, so we check for it explicitly. 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']}") class Vapi: