fix: handle Claude Code 5-hour rate limit errors gracefully

- Detect 5-hour rate limit errors in Claude Code provider
- Replace verbose error messages containing system prompts with a clean, user-friendly message
- Add translation key for rate limit message

Fixes #7778
This commit is contained in:
Roo Code 2025-09-08 10:48:13 +00:00
parent 25717817a6
commit 3ab7a3db14
2 changed files with 23 additions and 1 deletions

View file

@ -82,9 +82,30 @@ export class ClaudeCodeHandler extends BaseProvider implements ApiHandler {
const error = this.attemptParse(errorMessage)
if (!error) {
// Check if this is a 5-hour rate limit error
// These errors typically contain system prompts and are very long
if (
content.text.includes("5-hour") ||
content.text.includes("5 hour") ||
content.text.includes("rate limit") ||
content.text.includes("quota")
) {
throw new Error(t("common:errors.claudeCode.rateLimitReached"))
}
throw new Error(content.text)
}
// Check for 5-hour rate limit in parsed error
if (
error.error?.message &&
(error.error.message.includes("5-hour") ||
error.error.message.includes("5 hour") ||
error.error.message.includes("rate limit") ||
error.error.message.includes("quota"))
) {
throw new Error(t("common:errors.claudeCode.rateLimitReached"))
}
if (error.error.message.includes("Invalid model name")) {
throw new Error(
content.text + `\n\n${t("common:errors.claudeCode.apiKeyModelPlanMismatch")}`,

View file

@ -85,7 +85,8 @@
"processExitedWithError": "Claude Code process exited with code {{exitCode}}. Error output: {{output}}",
"stoppedWithReason": "Claude Code stopped with reason: {{reason}}",
"apiKeyModelPlanMismatch": "API keys and subscription plans allow different models. Make sure the selected model is included in your plan.",
"notFound": "Claude Code executable '{{claudePath}}' not found.\n\nPlease install Claude Code CLI:\n1. Visit {{installationUrl}} to download Claude Code\n2. Follow the installation instructions for your operating system\n3. Ensure the 'claude' command is available in your PATH\n4. Alternatively, configure a custom path in Roo settings under 'Claude Code Path'\n\nOriginal error: {{originalError}}"
"notFound": "Claude Code executable '{{claudePath}}' not found.\n\nPlease install Claude Code CLI:\n1. Visit {{installationUrl}} to download Claude Code\n2. Follow the installation instructions for your operating system\n3. Ensure the 'claude' command is available in your PATH\n4. Alternatively, configure a custom path in Roo settings under 'Claude Code Path'\n\nOriginal error: {{originalError}}",
"rateLimitReached": "5-hour usage limit reached. Please wait for the limit to reset before continuing."
},
"gemini": {
"generate_stream": "Gemini generate context stream error: {{error}}",