From 8d391e7811e9faac9e3d7423671c9a9f785fc2a7 Mon Sep 17 00:00:00 2001 From: Amey Balekundri Date: Wed, 30 Oct 2024 19:19:01 +0530 Subject: [PATCH] api error handling --- aryaxai/client/client.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/aryaxai/client/client.py b/aryaxai/client/client.py index 10cf8f8..06e17a5 100644 --- a/aryaxai/client/client.py +++ b/aryaxai/client/client.py @@ -85,10 +85,15 @@ def base_request(self, method, uri, payload={}, files=None, stream=False): files=files, stream=stream, ) + res = None + try: + res = response.json().get("details") or response.json() + except Exception: + res = response.text if 400 <= response.status_code < 500: - raise Exception(response.json()) + raise Exception(res) elif 500 <= response.status_code < 600: - raise Exception(response.text) + raise Exception(res) else: return response except Exception as e: