fix: Surface billing-related errors to the user #2324
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.
Problem:
Currently, when a user exceeds their monthly request limit for a service like Copilot, the application does not provide any specific feedback. This leads to a confusing user experience where the service silently stops working, leaving the request hanging and the user unsure of the cause.
Solution:
This change introduces proper handling for billing-related errors to ensure users receive clear and actionable feedback.
A new, specific
PaymentRequiredError
has been created to represent this state. This error contains a static, user-friendly message explaining that the service requires payment or a subscription check.The OpenAI completion service has been updated to detect HTTP
402
status codes in API responses.When a
402
error is detected, it is wrapped in the newPaymentRequiredError
and thrown. The frontend will present the message of this error to the user.Impact:
Users who have exceeded their usage limits will now see a clear error message explaining the issue, allowing them to take corrective action (e.g., checking their subscription or billing status). This significantly improves transparency and the overall user experience by turning a silent failure into actionable feedback.
Testing:
Unit tests have been added to verify that:
402
status code correctly results in aPaymentRequiredError
.