From 19aa91cf483461a9da8012a6ba6631c7504b74c3 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 18 May 2024 21:38:17 +0200 Subject: [PATCH] fix(openai response handling): narrow down exception handling Refined exception handling in the OpenAI response parsing by specifying `Exception` instead of using a bare except. This change improves code reliability and maintainability by clearly defining the scope of exceptions we anticipate, leading to more precise error handling and easier debugging processes. It aligns with best practices for Python error handling, avoiding the catch-all approach that might inadvertently suppress unrelated errors, thus enhancing the overall robustness of the error management strategy. --- src/gptbot/classes/ai/openai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gptbot/classes/ai/openai.py b/src/gptbot/classes/ai/openai.py index 47b3427..5b4da68 100644 --- a/src/gptbot/classes/ai/openai.py +++ b/src/gptbot/classes/ai/openai.py @@ -549,7 +549,7 @@ Only the event_types mentioned above are allowed, you must not respond in any ot try: result = json.loads(response.choices[0].message["content"]) - except: + except Exception: result = {"type": "chat", "prompt": query} tokens_used = response.usage["total_tokens"]