Skip to content

Commit

Permalink
Improve sub cancellation error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Apr 27, 2023
1 parent 78ac7d0 commit 26a4f21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/components/settings/settings-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ class SettingsPage extends React.Component<SettingsPageProps> {

this.props.accountStore.cancelSubscription().catch((e) => {
alert(e.message);
reportError(e);
});
};
}
Expand Down
25 changes: 15 additions & 10 deletions src/model/account/account-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,21 @@ export class AccountStore {
}

cancelSubscription = flow(function * (this: AccountStore) {
yield cancelSubscription();

console.log('Subscription cancel requested');
this.isAccountUpdateInProcess = true;
yield this.waitForUserUpdate(() =>
!this.user.subscription ||
this.user.subscription.status === 'deleted'
);
this.isAccountUpdateInProcess = false;
console.log('Subscription cancellation confirmed');
try {
this.isAccountUpdateInProcess = true;
yield cancelSubscription();
yield this.waitForUserUpdate(() =>
!this.user.subscription ||
this.user.subscription.status === 'deleted'
);
console.log('Subscription cancellation confirmed');
} catch (e: any) {
console.log(e);
reportError(`Subscription cancellation failed: ${e.message || e}`);
throw e;
} finally {
this.isAccountUpdateInProcess = false;
}
});

}

0 comments on commit 26a4f21

Please sign in to comment.