fix(api): wrap billing org-lookup errors in proper connect codes#1682
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThree org-lookup helper methods in the Connect API handler are refactored to translate underlying service and domain errors into gRPC Connect error responses with specific status codes (not-found, invalid-argument, internal) instead of returning raw errors. ChangesConnect error translation for org-lookup helpers
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Coverage Report for CI Build 27103920157Coverage decreased (-0.02%) to 43.2%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Summary
GetOrgIDFromBillingAccountID,GetOrgIDFromSubscriptionID, andGetOrgIDFromCheckoutIDare called exclusively from the authorization interceptor (authorization.go) to infer the org ID for billing-related endpoints. The authZ interceptor does not handle their errors — it passes them through as-is viareturn nil, err.On main, these functions return raw Go errors (e.g.
customer.ErrNotFound), which are not*connect.Error. Connect treats non-connect errors asCodeUnknown, so the client seescode_0/unknown(500) with the raw internal message leaked (e.g. "customer not found"). This was the root cause of a production alert onGetBillingBalanceandGetBillingAccount.This PR wraps all error paths in those three functions with proper Connect codes:
ErrNotFound→CodeNotFound(404)ErrInvalidUUID/ErrInvalidID→CodeInvalidArgument(400)CodeInternalwith genericErrInternalServerErrorsentinelBreaking changes
Billing, subscription, and checkout endpoints that previously returned
code_0/unknown(500) for missing resources now returnnot_found(404) orinvalid_argument(400).Test plan
go test ./internal/api/v1beta1connect/...— existing handler tests passgo build ./...— full build passes