devchat-ai / devchat

Automate your dev tasks with AI-powered scripts, from your IDE's chat panel.
https://www.devchat.ai
Apache License 2.0
342 stars 39 forks source link

Trim Leading and Trailing Spaces from KEY to Prevent Misleading openai.APIConnectionError #282

Closed runjinz closed 5 months ago

runjinz commented 6 months ago

Issue Description

When a KEY contains spaces, it triggers an h11._util.LocalProtocolError: Illegal header value. While handling this exception, the openai library rethrows it as openai.APIConnectionError: Connection error. This misleads users into thinking there is a network connection issue when, in reality, the problem lies with the formatting of the KEY.

Suggested Enhancement

To prevent this misinterpretation and avoid such exceptions, it would be beneficial to implement a pre-check that trims leading and trailing spaces from the KEY before any operations are performed. This simple preprocessing step could save users from encountering misleading errors and ensure more accurate error handling.

Rationale

Trimming spaces from the KEY not only aligns with standard best practices for handling user input but also enhances the user experience by reducing the occurrence of confusing errors. This adjustment would make the error messages more relevant and helpful to users, thereby improving overall reliability and trust in the library.