toeverything/AFFiNE · warning · SubscriptionHasBeenCanceled

subscription_has_been_canceled

subscription_has_been_canceled

Error message

Your subscription has already been canceled.

What it means

Thrown by cancelSubscription when subscription.canceledAt is already set, i.e. the subscription was canceled before (scheduled to end at period end) and another cancel request arrives. Double-cancel is treated as a state error rather than a no-op.

Solutions

  1. After a successful cancel, immediately mark the row canceled in local state and disable the Cancel control.
  2. Make client cancel idempotent: on this code, refresh subscriptions and treat the plan as already canceled instead of surfacing an error.
  3. Send the Idempotency-Key header on cancel calls so genuine network retries converge on one operation.

Example fix

// before
await svc.cancelSubscription(identity);

// after
try {
  await svc.cancelSubscription(identity, undefined, idempotencyKey);
} catch (e) {
  if (gqlErrorCode(e) === 'subscription_has_been_canceled') {
    return refreshSubscriptions(); // converge on server truth
  }
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (subscription.canceledAt) {
  showAlreadyCanceledState();
} else {
  await svc.cancelSubscription(identity, idempotencyKey);
}

Type guard

function isAlreadyCanceled(s: { canceledAt: Date | string | null }): boolean {
  return s.canceledAt !== null;
}

Try / catch

catch (e) { if (gqlErrorCode(e) === 'subscription_has_been_canceled') { await refreshSubscriptions(); markCanceledInUI(); return; } throw e; }

Prevention

When it happens

Trigger: User clicks Cancel twice (double click, or two tabs); retry of an idempotent-key-less cancel after the first succeeded; UI state not updated after the first cancel so the button stays enabled.

Common situations: Flaky network triggers client retry after the server already committed; webhook and user action both try to cancel; back-end job and manual action race.

Related errors


AI-assisted analysis of toeverything/AFFiNE@d897bb3d84 (2026-08-18). Data as JSON: /api/errors/9a80dee66bd9a591. Report an issue: GitHub.

Appendix: source

Thrown at packages/backend/server/src/plugins/payment/service.ts:208

    idempotencyKey?: string
  ) {
    const target = subscriptionTarget(identity);
    const subscription = await this.command<Subscription>({
      action: 'update_recurring',
      actorUserId: target.actor,
      targetType: target.type,
      targetId: target.id,
      plan: identity.plan,
      recurring,
      intentId: idempotencyKey ?? randomUUID(),
    });
    return normalizeSubscription(subscription);
  }

  async updateSubscriptionQuantity(
    identity: SubscriptionIdentity,
    quantity: number
  ) {
    const target = subscriptionTarget(identity);
    await this.command({
      action: 'update_quantity',
      actorUserId: target.actor,
      targetType: target.type,
      targetId: target.id,
      plan: identity.plan,
      quantity,
      intentId: randomUUID(),
    });
  }

  async generateLicenseKey(sessionId: string) {
    if (!sessionId) throw new InvalidLicenseSessionId();
    return this.command<string>({
      action: 'reveal_license',
      sessionId,
      intentId: randomUUID(),

View on GitHub (pinned to d897bb3d84)