feat: improve HTTP 402 error handling for all providers #10523
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR attempts to address Issue #10016. Feedback and guidance are welcome.
Problem
When API providers return HTTP status codes like 402 (Payment Required / insufficient balance), users see a generic "Unknown API error. Please contact Roo Code support." message instead of a user-friendly message like "You seem to have run out of funds/credits in your account."
The UI (ChatRow.tsx) already has localized messages for common HTTP status codes (400, 401, 402, 403, 429, 500) but they were not being shown because the error message format did not allow the UI to extract the status code.
Solution
Modified
handleProviderErrorinsrc/api/providers/utils/error-handler.tsto prefix error messages with the HTTP status code when status >= 400.Before:
DeepSeek completion error: Insufficient balanceAfter:
402 - DeepSeek completion error: Insufficient balanceThis allows the UI to:
Changes
handleProviderErrorto prefix error messages with HTTP status codes >= 400Testing
All existing and new tests pass:
error-handler.spec.tsopenai-error-handler.spec.tsdeepseek.spec.tsCloses #10016
Important
Enhances
handleProviderErrorto prefix error messages with HTTP status codes for improved UI error handling.handleProviderErrorinerror-handler.tsnow prefixes error messages with HTTP status codes for errors with status >= 400.error-handler.spec.tsfor HTTP 402, 401, 403, 429, and 500 error handling.handleOpenAIErrorremains an alias forhandleProviderErrorwith a default "completion" prefix.This description was created by
for e91bb85. You can customize this summary. It will automatically update as commits are pushed.