From edc02b592526bc7fb4e25f2e9ce1d6294937a3d1 Mon Sep 17 00:00:00 2001 From: Jonas Heller <168646044+jheller1212@users.noreply.github.com> Date: Wed, 24 Jun 2026 20:41:46 +0200 Subject: [PATCH] Show a clear rate-limit (429) message instead of generic network error After the retry loop exhausts on a 429, the error fell into the generic 'failed to fetch / check your API key + CORS' branch, which is confusing and wrong. A 429 is the most likely classroom failure when many participants share one key. Add an explicit 429 branch with actionable guidance (wait, lower messages-per-bot, add response delay). Hoist the provider-name map so the 401 and 429 branches share it. --- src/hooks/useConversationEngine.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hooks/useConversationEngine.ts b/src/hooks/useConversationEngine.ts index bf5b734..a640d62 100644 --- a/src/hooks/useConversationEngine.ts +++ b/src/hooks/useConversationEngine.ts @@ -231,12 +231,14 @@ export function useConversationEngine(opts: ConversationEngineOptions) { let msg = error instanceof Error ? (error.name === 'AbortError' ? 'Request timed out. Please try again.' : error.message) : 'An unknown error occurred'; + const providerNames: Record = { + gpt4: 'OpenAI', claude: 'Anthropic', gemini: 'Google Gemini', mistral: 'Mistral', + }; + const who = providerNames[config.model] || 'provider'; if (error instanceof APIError && (error.status === 401 || error.status === 403)) { - const providerNames: Record = { - gpt4: 'OpenAI', claude: 'Anthropic', gemini: 'Google Gemini', mistral: 'Mistral', - }; - const who = providerNames[config.model] || 'provider'; msg = `The ${who} API key looks invalid or unauthorized (HTTP ${error.status}). Please double-check the key — it may be mistyped, expired, or lack access to this model — then update it and start again.`; + } else if (error instanceof APIError && error.status === 429) { + msg = `The ${who} API is rate-limiting requests (HTTP 429) — too many were sent too quickly. Wait a moment, then start again. In a workshop where many people share one API key this is common: lower "messages per bot" or add a response delay in Advanced Settings to ease the load.`; } else if (msg.toLowerCase().includes('failed to fetch') || msg.toLowerCase().includes('network')) { msg += ' — Troubleshooting: (1) Is your API key copied correctly and complete? (2) Is the key still active and not expired? (3) Does your API account have available credits? (4) Check your browser console for CORS errors.'; }