Skip to content

fix(api): wrap billing org-lookup errors in proper connect codes#1682

Merged
rohilsurana merged 1 commit into
mainfrom
fix/billing-response-codes
Jun 8, 2026
Merged

fix(api): wrap billing org-lookup errors in proper connect codes#1682
rohilsurana merged 1 commit into
mainfrom
fix/billing-response-codes

Conversation

@rohilsurana

@rohilsurana rohilsurana commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary

GetOrgIDFromBillingAccountID, GetOrgIDFromSubscriptionID, and GetOrgIDFromCheckoutID are 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 via return nil, err.

On main, these functions return raw Go errors (e.g. customer.ErrNotFound), which are not *connect.Error. Connect treats non-connect errors as CodeUnknown, so the client sees code_0 / unknown (500) with the raw internal message leaked (e.g. "customer not found"). This was the root cause of a production alert on GetBillingBalance and GetBillingAccount.

This PR wraps all error paths in those three functions with proper Connect codes:

  • ErrNotFoundCodeNotFound (404)
  • ErrInvalidUUID / ErrInvalidIDCodeInvalidArgument (400)
  • Everything else → CodeInternal with generic ErrInternalServerError sentinel

Breaking changes

Billing, subscription, and checkout endpoints that previously returned code_0 / unknown (500) for missing resources now return not_found (404) or invalid_argument (400).

Test plan

  • go test ./internal/api/v1beta1connect/... — existing handler tests pass
  • go build ./... — full build passes

@vercel

vercel Bot commented Jun 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Jun 7, 2026 8:29pm

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a49772c3-744b-497a-a597-9dfd4ba6663c

📥 Commits

Reviewing files that changed from the base of the PR and between bd6a145 and d7c5ba6.

📒 Files selected for processing (1)
  • internal/api/v1beta1connect/v1beta1connect.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved API error responses with proper status code classification for different error types including not found, invalid input, and server errors.

Walkthrough

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

Changes

Connect error translation for org-lookup helpers

Layer / File(s) Summary
Error handling imports
internal/api/v1beta1connect/v1beta1connect.go
Import connectrpc.com/connect and github.com/raystack/frontier/pkg/errors to enable Connect error construction and domain error detection.
Org-lookup error translation helpers
internal/api/v1beta1connect/v1beta1connect.go
GetOrgIDFromSubscriptionID, GetOrgIDFromCheckoutID, and GetOrgIDFromBillingAccountID classify subscription, checkout, and customer lookup errors using error type detection (errors.Is) and return typed Connect error responses (CodeNotFound, CodeInvalidArgument, CodeInternal) instead of raw errors.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • whoAbhishekSah
  • rsbh
  • AmanGIT07
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 27103920157

Coverage decreased (-0.02%) to 43.2%

Details

  • Coverage decreased (-0.02%) from the base build.
  • Patch coverage: 36 uncovered changes across 1 file (0 of 36 lines covered, 0.0%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
internal/api/v1beta1connect/v1beta1connect.go 36 0 0.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 38065
Covered Lines: 16444
Line Coverage: 43.2%
Coverage Strength: 12.13 hits per line

💛 - Coveralls

@rohilsurana rohilsurana merged commit 9558e83 into main Jun 8, 2026
8 checks passed
@rohilsurana rohilsurana deleted the fix/billing-response-codes branch June 8, 2026 06:09
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