diff --git a/pages/setup/account.page.test.tsx b/pages/setup/account.page.test.tsx index 9bbf9a3e9..3d320a130 100644 --- a/pages/setup/account.page.test.tsx +++ b/pages/setup/account.page.test.tsx @@ -113,6 +113,25 @@ describe('getServerSideProps', () => { ); }); + it('swallows server-side mutation errors', async () => { + const accountListOptions = { + accountLists: { + nodes: [{ id: 'account-list-1' }], + }, + }; + query.mockResolvedValue({ + data: accountListOptions, + }); + mutate.mockRejectedValue(new Error('Failed')); + + await expect(getServerSideProps(context)).resolves.toEqual({ + props: { + accountListOptions, + session, + }, + }); + }); + it('does not set an account list as the default when there are multiple', async () => { const accountListOptions = { accountLists: { diff --git a/pages/setup/account.page.tsx b/pages/setup/account.page.tsx index 958776055..dbce25ba5 100644 --- a/pages/setup/account.page.tsx +++ b/pages/setup/account.page.tsx @@ -115,25 +115,32 @@ export const getServerSideProps: GetServerSideProps = async ( if (accountListOptions.accountLists.nodes.length === 1) { // The user has exactly one account list, so set it as the default and go to preferences const defaultAccountListId = accountListOptions.accountLists.nodes[0].id; - await ssrClient.mutate< - UpdateUserDefaultAccountMutation, - UpdateUserDefaultAccountMutationVariables - >({ - mutation: UpdateUserDefaultAccountDocument, - variables: { - input: { - attributes: { - defaultAccountList: defaultAccountListId, + try { + await ssrClient.mutate< + UpdateUserDefaultAccountMutation, + UpdateUserDefaultAccountMutationVariables + >({ + mutation: UpdateUserDefaultAccountDocument, + variables: { + input: { + attributes: { + defaultAccountList: defaultAccountListId, + }, }, }, - }, - }); - return { - redirect: { - destination: `/accountLists/${defaultAccountListId}/settings/preferences`, - permanent: false, - }, - }; + }); + return { + redirect: { + destination: `/accountLists/${defaultAccountListId}/settings/preferences`, + permanent: false, + }, + }; + } catch { + // If setting the account list failed, silently swallow the error and let + // the user view the page. If the error is persistent, the mutation will + // fail there when they try to choose a default account list, and they + // will at least get an error message. + } } return {