Skip to content

fix(bug): rescue BaseService::ThrottlingError when calculating Custom… #3653

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

Merged
merged 3 commits into from
May 28, 2025

Conversation

mariohd
Copy link
Contributor

@mariohd mariohd commented May 15, 2025

Problem

::Invoices::CustomerUsageService can raise BaseService::ThrottlingError when apply_taxes is true and customer_provider_taxation? is true.

If the controller does not handle this, the user will receive a 500 error.

This PR does not fix the throttling error because its out of our control, but inform the user to try again later in a nicer way than a error 500.

Sentry error

https://lago.sentry.io/issues/6336411980/?project=6370067

Steps to reproduce

Have an organization with Anrok provider configured
Have a invoice for an Anrok customer

call api GET customers/<customer_external_id>/current_usage.
Apply taxes is true by default.
The ThrottlingError may be raised and return a 500 error.

Result

With the rescue in place, the user would get a response like this when ThrottlingError happens

{
"status" => 429,
 "error" => "Too Many Provider Requests",
 "code" => "too_many_provider_requests",
 "error_details" => { 
      "provider_name" => "anrok",
      "message" => "Service anrok is not available. Try again later."
  }
}

@mariohd mariohd requested review from julienbourdeau and rsempe May 15, 2025 14:32
@mariohd mariohd force-pushed the fix/throttling-error-on-usage-controller branch from 413302a to 248a02b Compare May 16, 2025 13:08
@mariohd mariohd requested a review from julienbourdeau May 22, 2025 20:52
@mariohd mariohd force-pushed the fix/throttling-error-on-usage-controller branch from 6630352 to aa3bdcb Compare May 22, 2025 20:58
@mariohd mariohd force-pushed the fix/throttling-error-on-usage-controller branch from aa3bdcb to f40c32f Compare May 27, 2025 15:09
@mariohd mariohd requested a review from julienbourdeau May 27, 2025 16:48
@mariohd mariohd merged commit fd60d18 into main May 28, 2025
14 checks passed
@mariohd mariohd deleted the fix/throttling-error-on-usage-controller branch May 28, 2025 12:51
diegocharles pushed a commit that referenced this pull request Jun 2, 2025
#3653)

### Problem
`::Invoices::CustomerUsageService` can raise
`BaseService::ThrottlingError` when `apply_taxes` is `true` and
`customer_provider_taxation?` is `true`.

If the controller does not handle this, the user will receive a 500
error.

This PR does not fix the throttling error because its out of our
control, but inform the user to try again later in a nicer way than a
error 500.
#### Sentry error
https://lago.sentry.io/issues/6336411980/?project=6370067

##
### Steps to reproduce
Have an organization with Anrok provider configured
Have a invoice for an Anrok customer

call api GET `customers/<customer_external_id>/current_usage`. 
Apply taxes is `true` by default.
The ThrottlingError may be raised and return a 500 error.
##
### Result
With the rescue in place, the user would get a response like this when
ThrottlingError happens

```
{
"status" => 429,
 "error" => "Too Many Provider Requests",
 "code" => "too_many_provider_requests",
 "error_details" => { 
      "provider_name" => "anrok",
      "message" => "Service anrok is not available. Try again later."
  }
}
 ```
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.

3 participants