Skip to content

Commit

Permalink
Added statement to handle HTTP responses > 400
Browse files Browse the repository at this point in the history
  • Loading branch information
fsantamaria1 committed Aug 17, 2023
1 parent 24f5ba0 commit d302e8a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions server/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d302e8a

Please sign in to comment.