mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-09 03:07:46 +08:00
feat(chat): show a quota hint when the server's key is refused (#953)
On the server's own credentials a provider 403 now gets its own code, server_key_forbidden, with a hint in all four languages: today's free quota is used up, it resets tomorrow, and users can add their own key in model settings. The generic "The provider returned an error." line is left out for this code. A daily spend cap that blocks a shared key makes every call return 403. The old hint said the key may lack access to the model or region, which points users at a setting they cannot change. A 403 on the user's own key keeps the old hint and the provider's text.
This commit is contained in:
+9
-1
@@ -24,6 +24,8 @@ export type LLMErrorCode =
|
||||
| "provider_unavailable"
|
||||
| "cannot_connect"
|
||||
| "timeout"
|
||||
// A 403 on the server's own key, e.g. a daily spend cap blocked it
|
||||
| "server_key_forbidden"
|
||||
| "unknown"
|
||||
|
||||
export interface LLMError {
|
||||
@@ -130,7 +132,13 @@ export function streamErrorText(error: unknown, hideDetails = false): string {
|
||||
const classified = classifyLLMError(error)
|
||||
if (hideDetails) {
|
||||
console.error("[chat] Provider error:", error)
|
||||
classified.message = "The provider returned an error."
|
||||
if (classified.code === "forbidden") {
|
||||
// The hint says all the user can do; there is no message to add
|
||||
classified.code = "server_key_forbidden"
|
||||
classified.message = ""
|
||||
} else {
|
||||
classified.message = "The provider returned an error."
|
||||
}
|
||||
}
|
||||
return JSON.stringify(classified)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user