diff --git a/packages/subscription-controller/CHANGELOG.md b/packages/subscription-controller/CHANGELOG.md index cca8846d3b8..56c3a25d048 100644 --- a/packages/subscription-controller/CHANGELOG.md +++ b/packages/subscription-controller/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- **BREAKING:** `getBenefits` returns an ineligible benefits response instead of throwing `UserNotSubscribed`. ([#10994](https://github.com/MetaMask/core/pull/10994)) - **BREAKING:** Remove `builderCode` from `PerpsBenefitUsage` and from benefits-response validation. The Perps benefits payload no longer includes it, and requiring the field rejected otherwise valid responses. ([#10995](https://github.com/MetaMask/core/pull/10995)) ## [14.0.2] diff --git a/packages/subscription-controller/src/SubscriptionController-method-action-types.ts b/packages/subscription-controller/src/SubscriptionController-method-action-types.ts index 65a941235b3..d340e9f81ba 100644 --- a/packages/subscription-controller/src/SubscriptionController-method-action-types.ts +++ b/packages/subscription-controller/src/SubscriptionController-method-action-types.ts @@ -23,9 +23,13 @@ export type SubscriptionControllerGetSubscriptionsAction = { /** * Gets and stores the user's subscription benefits. * - * @returns The benefits response. - * @throws If the user is not an active Money Account Plus subscriber or is - * not eligible for benefits. + * An ineligible response is a normal result. Persisted benefits are cleared + * and the response is returned so callers can branch on `eligible`. That + * includes a provisional subscription whose benefits are not ready yet, + * which is distinct from having no active Money Account Plus subscription. + * + * @returns The benefits response, including when `eligible` is false. + * @throws If the user is not an active Money Account Plus subscriber. */ export type SubscriptionControllerGetBenefitsAction = { type: `SubscriptionController:getBenefits`; diff --git a/packages/subscription-controller/src/SubscriptionController.test.ts b/packages/subscription-controller/src/SubscriptionController.test.ts index dcb6e27a126..3141a38722c 100644 --- a/packages/subscription-controller/src/SubscriptionController.test.ts +++ b/packages/subscription-controller/src/SubscriptionController.test.ts @@ -817,7 +817,7 @@ describe('SubscriptionController', () => { ); }); - it('should clear benefits state before throwing UserNotSubscribed for an ineligible response', async () => { + it('should clear benefits state and return an ineligible response', async () => { await withController( { state: { @@ -830,12 +830,11 @@ describe('SubscriptionController', () => { MOCK_INELIGIBLE_BENEFITS_RESPONSE, ); - await expect( - rootMessenger.call('SubscriptionController:getBenefits'), - ).rejects.toThrow( - SubscriptionControllerErrorMessage.UserNotSubscribed, + const result = await rootMessenger.call( + 'SubscriptionController:getBenefits', ); + expect(result).toStrictEqual(MOCK_INELIGIBLE_BENEFITS_RESPONSE); expect(controller.state.benefits).toBeUndefined(); expect(mockService.getBenefits).toHaveBeenCalledTimes(1); }, diff --git a/packages/subscription-controller/src/SubscriptionController.ts b/packages/subscription-controller/src/SubscriptionController.ts index cbce479b240..55d9fde9bf7 100644 --- a/packages/subscription-controller/src/SubscriptionController.ts +++ b/packages/subscription-controller/src/SubscriptionController.ts @@ -439,9 +439,13 @@ export class SubscriptionController extends StaticIntervalPollingController()< /** * Gets and stores the user's subscription benefits. * - * @returns The benefits response. - * @throws If the user is not an active Money Account Plus subscriber or is - * not eligible for benefits. + * An ineligible response is a normal result. Persisted benefits are cleared + * and the response is returned so callers can branch on `eligible`. That + * includes a provisional subscription whose benefits are not ready yet, + * which is distinct from having no active Money Account Plus subscription. + * + * @returns The benefits response, including when `eligible` is false. + * @throws If the user is not an active Money Account Plus subscriber. */ async getBenefits(): Promise { this.#assertIsActiveMoneyAccountPlusSubscriber(); @@ -464,10 +468,6 @@ export class SubscriptionController extends StaticIntervalPollingController()< : undefined; }); - if (!benefits.eligible) { - throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed); - } - return benefits; }