{"record":{"id":"eb5e8d3b7172ee59","repo":"toeverything/AFFiNE","slug":"customer-portal-create-failed","errorCode":"customer_portal_create_failed","errorMessage":"Failed to create customer portal session.","messagePattern":"Failed to create customer portal session\\.","errorType":"exception","errorClass":"CustomerPortalCreateFailed","httpStatus":500,"severity":"error","filePath":"packages/backend/server/src/plugins/payment/license/controller.ts","lineNumber":273,"sourceCode":"    const subscriptionData =\n      await this.stripeProvider.stripe.subscriptions.retrieve(\n        subscription.externalSubscriptionId,\n        {\n          expand: ['customer'],\n        }\n      );\n\n    const customer = subscriptionData.customer as Stripe.Customer;\n    try {\n      const portal =\n        await this.stripeProvider.stripe.billingPortal.sessions.create({\n          customer: customer.id,\n        });\n\n      return { url: portal.url };\n    } catch (e) {\n      this.logger.error('Failed to create customer portal.', e);\n      throw new CustomerPortalCreateFailed();\n    }\n  }\n\n  license(subscription: Subscription) {\n    return {\n      plan: subscription.plan,\n      recurring: subscription.recurring,\n      quantity: subscription.quantity,\n      endAt: subscription.end?.getTime(),\n    };\n  }\n}\n","sourceCodeStart":255,"sourceCodeEnd":286,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/backend/server/src/plugins/payment/license/controller.ts#L255-L286","documentation":"createCustomerPortal catches Stripe billing portal session creation failures, logs them, and rethrows the typed CustomerPortalCreateFailed so callers get a stable error instead of a raw Stripe SDK exception.","triggerScenarios":"Thrown at packages/backend/server/src/plugins/payment/license/controller.ts:273 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the payment provider (Stripe) configuration and API keys on the server.","Ensure the customer exists in the payment system before creating a portal session.","Retry later; if persistent, inspect server logs for the upstream payment error."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}