Skip to content

Commit f26349e

Browse files
fix(billing): address review nits — 402 catch-all + null-check consistency
- 402 catch-all in requireQuota middleware no longer surfaces err.message verbatim. The service only throws known types today (PAYMENT_PAST_DUE / METER_EXHAUSTED) which are mapped explicitly above; an unknown 402 sub-type added later would leak the message. Send a generic "Payment required" phrase instead — new sub-types must be mapped explicitly above the catch-all. - billing.quota.service.js: normalize the null-check style on the active plan lookup. Both branches treat "plan not configured" the same way; pick the !activePlan shape to match the freePlan branch above. All 1666 billing unit tests pass.
1 parent e09ac2c commit f26349e

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

modules/billing/middlewares/billing.requireQuota.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ function requireQuota(resource, action) {
6666
if (details?.type === 'METER_EXHAUSTED') {
6767
return responses.error(res, 402, 'Payment Required', 'Meter exhausted')(details);
6868
}
69-
return responses.error(res, 402, 'Payment Required', err.message)(details);
69+
// Defensive: an unknown 402 sub-type would leak err.message verbatim.
70+
// The service only throws known types today, so send the generic phrase
71+
// instead — any future 402 type must be mapped explicitly above.
72+
return responses.error(res, 402, 'Payment Required', 'Payment required')(details);
7073
}
7174
if (err.status === 429) {
7275
return responses.error(res, 429, 'Quota exceeded', 'You have reached the usage limit for this resource')(details);

modules/billing/services/billing.quota.service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async function assertCanExecute({ orgId, organization, user, resource, action })
125125
// No BillingUsage doc yet — fall back to plan quota
126126
const planId = subscription?.plan ?? getDefaultPlanId();
127127
const activePlan = BillingPlanService.getActivePlan(planId);
128-
if (activePlan === null || activePlan === undefined) {
128+
if (!activePlan) {
129129
throw new AppError('Billing plan configuration is temporarily unavailable', {
130130
status: 503,
131131
details: { type: 'PLAN_NOT_CONFIGURED', planId },

0 commit comments

Comments
 (0)