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
349 stars 41 forks source link

Handling Keys with Spaces Triggers Misleading Connection Error #295

Closed runjinz closed 7 months ago

runjinz commented 7 months ago

Issue description:

When a key contains spaces, it triggers an exception with the message h11._util.LocalProtocolError: Illegal header value. When this occurs, the OpenAI library rethrows this as an openai.APIConnectionError: Connection error., which can misleadingly suggest that the issue lies with network connectivity rather than with the key's formatting.

This has the potential to lead users down the wrong path when troubleshooting, as the real issue is related to the presence of spaces in the key. A beneficial enhancement would be to strip leading and trailing spaces from keys before they are used. Implementing a simple trim operation on keys can prevent this kind of exception from happening and improve user experience by providing more accurate error feedback.

Suggested change:

The goal of this change is to prevent Illegal header value exceptions related to key formatting and to ensure that errors thrown reflect the actual problem more accurately.