Skip to content

fix(referral): propagate reward completion errors to allow Stripe retry#28723

Open
PanAchy wants to merge 1 commit into
anomalyco:devfrom
PanAchy:fix/referral-silent-failure
Open

fix(referral): propagate reward completion errors to allow Stripe retry#28723
PanAchy wants to merge 1 commit into
anomalyco:devfrom
PanAchy:fix/referral-silent-failure

Conversation

@PanAchy
Copy link
Copy Markdown
Contributor

@PanAchy PanAchy commented May 21, 2026

Issue for this PR

Closes #28722

Type of change

  • Bug fix

What does this PR do?

Problem 1 — Silently swallowed errors:

The customer.subscription.created webhook called Referral.completeFromLiteSubscription(...) with .catch(console.error), swallowing any error and always returning 200 to Stripe. This means transient failures (DB errors, race conditions) never trigger Stripe's retry mechanism, permanently leaving the referral reward in pending.

Problem 2 — Spurious throws for non-referred subscribers:

completeFromLiteSubscription previously threw "Referral not found" when a subscriber had no referral row (i.e., the vast majority of subscribers). This meant every non-referred subscription was generating a swallowed error — noisy and masking real failures.

Fix:

  1. webhook.ts: Remove .catch(console.error). Let real errors propagate so Stripe retries on failure.
  2. referral.ts: Change completeFromLiteSubscription to return early (no-op) when no referral row exists for the invitee account. Non-referred subscribers now produce no error.
// Before — webhook.ts:
await Referral.completeFromLiteSubscription({ workspaceID, userID }).catch(
  console.error,
);

// After:
await Referral.completeFromLiteSubscription({ workspaceID, userID });
// Before — referral.ts:
if (!referral) throw new Error("Referral not found");

// After:
if (!referral) return;

How did you verify your code works?

  • Ran bun test test/referral.test.ts in packages/console/core — 1 pass, 0 fail.
  • Ran bun typecheck in packages/console/core and packages/console/app — no errors.
  • Confirmed non-referred subscribers resolve cleanly with the early return.
  • Confirmed the webhook now propagates real errors, enabling Stripe retry.

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Referral reward stuck in pending if reward completion fails silently

1 participant