mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-04-08 03:48:14 +02:00
somewhat clearer API errors (#2064)
This commit is contained in:
parent
bb7e1d6e55
commit
291e6c4198
@ -693,18 +693,28 @@ def stream_chat_message_objects(
|
||||
yield cast(ChatPacket, packet)
|
||||
|
||||
except Exception as e:
|
||||
logger.exception("Failed to process chat message")
|
||||
|
||||
# Don't leak the API key
|
||||
error_msg = str(e)
|
||||
if llm.config.api_key and llm.config.api_key.lower() in error_msg.lower():
|
||||
logger.exception(f"Failed to process chat message: {error_msg}")
|
||||
|
||||
if "Illegal header value b'Bearer '" in error_msg:
|
||||
error_msg = (
|
||||
f"LLM failed to respond. Invalid API "
|
||||
f"key error from '{llm.config.model_provider}'."
|
||||
f"Authentication error: Invalid or empty API key provided for '{llm.config.model_provider}'. "
|
||||
"Please check your API key configuration."
|
||||
)
|
||||
elif (
|
||||
"Invalid leading whitespace, reserved character(s), or return character(s) in header value"
|
||||
in error_msg
|
||||
):
|
||||
error_msg = (
|
||||
f"Authentication error: Invalid API key format for '{llm.config.model_provider}'. "
|
||||
"Please ensure your API key does not contain leading/trailing whitespace or invalid characters."
|
||||
)
|
||||
elif llm.config.api_key and llm.config.api_key.lower() in error_msg.lower():
|
||||
error_msg = f"LLM failed to respond. Invalid API key error from '{llm.config.model_provider}'."
|
||||
else:
|
||||
error_msg = "An unexpected error occurred while processing your request. Please try again later."
|
||||
|
||||
yield StreamingError(error=error_msg)
|
||||
# Cancel the transaction so that no messages are saved
|
||||
db_session.rollback()
|
||||
return
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user