Skip to content

fix: Surface billing-related errors to the user #2324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dustinbyrne
Copy link
Contributor

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.

  1. 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.

  2. The OpenAI completion service has been updated to detect HTTP 402 status codes in API responses.

  3. When a 402 error is detected, it is wrapped in the new PaymentRequiredError 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:

  • An API error with a 402 status code correctly results in a PaymentRequiredError.
  • The new error is propagated correctly through the completion service and is not retried.
image

This includes cases where the Copilot request limit is exceeded.
@dustinbyrne dustinbyrne requested a review from Copilot July 11, 2025 16:38
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces proper handling for billing-related errors by creating a new PaymentRequiredError class and integrating it with the OpenAI completion service to provide clear user feedback when payment or subscription issues occur.

Key changes:

  • Added a new PaymentRequiredError exception class with a user-friendly message
  • Updated OpenAI completion service to detect HTTP 402 status codes and throw the new error
  • Added comprehensive test coverage for the new error handling behavior

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/navie/src/services/completion-service.ts Defines the new PaymentRequiredError class and adds error handling logic
packages/navie/src/services/openai-completion-service.ts Implements HTTP 402 status code detection and error throwing
packages/navie/test/services/completion-service.spec.ts Adds unit tests for the base completion service error handling
packages/navie/test/services/openai-completion-service.spec.ts Adds unit tests for OpenAI-specific 402 error handling

@dustinbyrne
Copy link
Contributor Author

It's worth mentioning that I think our error handling overall looks like it's in need of some improvements. Other 4xx errors may be causing the same sort of erroneous behavior (hanging requests, no user feedback). I think that may be a good follow on item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant