-
Notifications
You must be signed in to change notification settings - Fork 215
fix(rpc): catch billing resolution errors in getBilling() to enable free-tier fallback #790
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
base: staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import { | |
| import { runTracked } from "./middleware/track-mutation"; | ||
| import { runAuditedMutation } from "./middleware/audit-mutation"; | ||
| import { type BillingOwner, getBillingOwner } from "./utils/billing"; | ||
| import { logger } from "./lib/logger"; | ||
| import { getOrganizationOwnerId } from "./utils/organization"; | ||
|
|
||
| export interface PreResolvedAuth { | ||
|
|
@@ -104,13 +105,20 @@ export const createRPCContext = async ( | |
| if (billingResolved) { | ||
| return billingCache; | ||
| } | ||
| if (user) { | ||
| billingCache = await getBillingOwner(user.id, organizationId); | ||
| } else if (apiKey?.organizationId) { | ||
| const ownerId = await getOrganizationOwnerId(apiKey.organizationId); | ||
| if (ownerId) { | ||
| billingCache = await getBillingOwner(ownerId, apiKey.organizationId); | ||
| try { | ||
| if (user) { | ||
| billingCache = await getBillingOwner(user.id, organizationId); | ||
| } else if (apiKey?.organizationId) { | ||
| const ownerId = await getOrganizationOwnerId(apiKey.organizationId); | ||
| if (ownerId) { | ||
| billingCache = await getBillingOwner(ownerId, apiKey.organizationId); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| logger.warn( | ||
| { error }, | ||
| "Failed to resolve billing owner; falling back to free tier" | ||
| ); | ||
| } | ||
| billingResolved = true; | ||
|
Comment on lines
+117
to
123
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new exception-to-free-tier behavior has no direct test coverage. Existing procedure tests inject mocked Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| return billingCache; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
AUTUMN_SECRET_KEYis missing, this catch makescontext.getBilling()returnundefined, butgetUsagethen callsgetAutumn().check()directly. That call throws the same missing-secret error and is converted into an internal RPC error, so local environments still cannot retrieve usage through the intended free-tier fallback. The fallback must also cover or avoid that second Autumn call.