xtekky / chatgpt-clone

ChatGPT interface with better UI
https://g4f.ai
GNU General Public License v3.0
3.45k stars 1.03k forks source link

Possible fix for Issues #79 and #103 #119

Closed fsantamaria1 closed 1 year ago

fsantamaria1 commented 1 year ago

I added this conditional statement:

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

The GUI displays the JSON, but it is descriptive enough.

image

This will help users troubleshoot when they are having API issues such as invalid API keys and expired free trials.