Repository navigation
fix: customer validation on subscription create - #3409
Conversation
📝 WalkthroughWalkthroughRefactors the subscription creation handler to rename a customer variable, restructure getCustomer with switch-based lookup by ID or Key, adjust error handling and messages with namespace/context, remove certain preliminary checks, and use the resolved customer ID in workflow inputs. No exported/public interfaces changed. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
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 |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
openmeter/productcatalog/subscription/http/create.go (4)
178-186: Guard against both id and key being provided (ambiguous input)If both are set, current logic silently prefers id. Consider rejecting the request explicitly.
Proposed change:
- switch { + // reject ambiguous inputs + if id != nil && *id != "" && key != nil && *key != "" { + return nil, models.NewGenericValidationError(fmt.Errorf("customer id and key are mutually exclusive")) + } + switch {If preferring one over the other is intentional, ignore this and please confirm.
190-199: Fix label in error message (should be customer.key, not customer.id)This is misleading during debugging/triage.
Apply:
- return nil, fmt.Errorf("failed to lookup customer by key [namespace=%s customer.id=%s]: %w", namespace, *key, err) + return nil, fmt.Errorf("failed to lookup customer by key [namespace=%s customer.key=%s]: %w", namespace, *key, err)
211-211: Return explicit nil error for clarityNo path reaches here with a non-nil err.
- return cus, err + return cus, nil
129-134: Avoid shadowing imported package name with local variableLocal var named customer shadows the imported customer package; prefer cus for consistency with the custom plan path.
- customer, err := h.getCustomer(ctx, ns, parsedBody.CustomerId, parsedBody.CustomerKey) + cus, err := h.getCustomer(ctx, ns, parsedBody.CustomerId, parsedBody.CustomerKey) if err != nil { return CreateSubscriptionRequest{}, fmt.Errorf("failed to get customer: %w", err) } @@ - CustomerID: customer.ID, + CustomerID: cus.ID,Also applies to: 146-147
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
openmeter/productcatalog/subscription/http/create.go(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
openmeter/productcatalog/subscription/http/create.go (2)
openmeter/customer/customer.go (3)
CustomerKey(119-122)CustomerID(104-104)GetCustomerInput(273-280)pkg/models/errors.go (1)
NewGenericValidationError(138-140)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: Quickstart
- GitHub Check: E2E
- GitHub Check: Build
- GitHub Check: Lint
- GitHub Check: Code Generators
- GitHub Check: Test
- GitHub Check: Migration Checks
- GitHub Check: Analyze (go)
🔇 Additional comments (2)
openmeter/productcatalog/subscription/http/create.go (2)
201-203: LGTM: clear validation error when neither id nor key providedGood user-facing error mapping.
86-89: LGTM: customer resolution and CustomerID wiring — error unwrapping verifiedfmt.Errorf uses %w (preserves the error chain); the subscription HTTP path uses commonhttp.HandleErrorIfTypeMatches (via openmeter/productcatalog/subscription/http/errors.go) and pkg/models helpers that delegate to errors.As, so wrapped GenericValidationError will be unwrapped and mapped by the encoder (see openmeter/productcatalog/subscription/http/create.go and pkg/framework/commonhttp/errors.go).
Overview
Map validation errors returned by Customer lookup for Subscription create operation.
Summary by CodeRabbit
Bug Fixes
Improvements