From d302e8ab2a3fffda1dbbaded7a86ea789d29df90 Mon Sep 17 00:00:00 2001 From: Fredy Santamaria Date: Thu, 17 Aug 2023 09:45:18 -0400 Subject: [PATCH] Added statement to handle HTTP responses > 400 --- server/backend.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/backend.py b/server/backend.py index 73bba12..18c7f23 100644 --- a/server/backend.py +++ b/server/backend.py @@ -78,6 +78,17 @@ def _conversation(self): stream = True ) + if gpt_resp.status_code >= 400: + error_data =gpt_resp.json().get('error', {}) + error_code = error_data.get('code', None) + error_message = error_data.get('message', "An error occurred") + return { + 'successs': False, + 'error_code': error_code, + 'message': error_message, + 'status_code': gpt_resp.status_code + }, gpt_resp.status_code + def stream(): for chunk in gpt_resp.iter_lines(): try: