A local-first personal finance app
:bug: (bank-sync) improved error handling for initial gocardless account linking (#4756)
Matiss Janis Aboltinsfe3fe47b67e4
diff --git a/packages/desktop-client/src/components/modals/GoCardlessExternalMsgModal.tsx b/packages/desktop-client/src/components/modals/GoCardlessExternalMsgModal.tsxindex bdc9a36d41..948bd1325c 100644--- a/packages/desktop-client/src/components/modals/GoCardlessExternalMsgModal.tsx+++ b/packages/desktop-client/src/components/modals/GoCardlessExternalMsgModal.tsx@@ -66,12 +66,18 @@ function useAvailableBanks(country: string) {};}-function renderError(error: 'unknown' | 'timeout', t: (key: string) => string) {+function renderError(+ error: { code: 'unknown' | 'timeout'; message?: string },+ t: ReturnType<typeof useTranslation>['t'],+) {return (- <Error style={{ alignSelf: 'center' }}>- {error === 'timeout'+ <Error style={{ alignSelf: 'center', marginBottom: 10 }}>+ {error.code === 'timeout'? t('Timed out. Please try again.')- : t('An error occurred while linking your account, sorry!')}+ : t(+ 'An error occurred while linking your account, sorry! The potential issue could be: {{ message }}',+ { message: error.message },+ )}</Error>);}@@ -94,7 +100,10 @@ export function GoCardlessExternalMsgModal({const [success, setSuccess] = useState<boolean>(false);const [institutionId, setInstitutionId] = useState<string>();const [country, setCountry] = useState<string>();- const [error, setError] = useState<'unknown' | 'timeout' | null>(null);+ const [error, setError] = useState<{+ code: 'unknown' | 'timeout';+ message?: string;+ } | null>(null);const [isGoCardlessSetupComplete, setIsGoCardlessSetupComplete] = useState<boolean | null>(null);@@ -116,7 +125,10 @@ export function GoCardlessExternalMsgModal({const res = await onMoveExternal({ institutionId });if ('error' in res) {- setError(res.error);+ setError({+ code: res.error,+ message: 'message' in res ? res.message : undefined,+ });setWaiting(null);return;}diff --git a/packages/loot-core/src/client/modals/modalsSlice.ts b/packages/loot-core/src/client/modals/modalsSlice.tsindex fb732dffbe..fcf59b9609 100644--- a/packages/loot-core/src/client/modals/modalsSlice.ts+++ b/packages/loot-core/src/client/modals/modalsSlice.ts@@ -117,7 +117,9 @@ export type Modal =onMoveExternal: (arg: {institutionId: string;}) => Promise<- { error: 'unknown' | 'timeout' } | { data: GoCardlessToken }+ | { error: 'timeout' }+ | { error: 'unknown'; message?: string }+ | { data: GoCardlessToken }>;onClose?: (() => void) | undefined;onSuccess: (data: GoCardlessToken) => Promise<void>;diff --git a/packages/loot-core/src/server/accounts/app.ts b/packages/loot-core/src/server/accounts/app.tsindex 9e522f74a7..44350efe87 100644--- a/packages/loot-core/src/server/accounts/app.ts+++ b/packages/loot-core/src/server/accounts/app.ts@@ -15,6 +15,7 @@ import {TransactionEntity,SyncServerSimpleFinAccount,SyncServerPluggyAiAccount,+ type GoCardlessToken,} from '../../types/models';import { createApp } from '../app';import * as db from '../db';@@ -550,14 +551,19 @@ async function pollGoCardlessWebToken({stopPolling = false;async function getData(- cb: (error: string | null, data?: unknown | undefined) => void,+ cb: (+ data:+ | { status: 'timeout' }+ | { status: 'unknown'; message?: string }+ | { status: 'success'; data: GoCardlessToken },+ ) => void,) {if (stopPolling) {return;}if (Date.now() - startTime >= 1000 * 60 * 10) {- cb('timeout');+ cb({ status: 'timeout' });return;}@@ -577,10 +583,11 @@ async function pollGoCardlessWebToken({);if (data) {- if (data.error) {- cb('unknown');+ if (data.error_code) {+ console.error('Failed linking gocardless account:', data);+ cb({ status: 'unknown', message: data.error_type });} else {- cb(null, data);+ cb({ status: 'success', data });}} else {setTimeout(() => getData(cb), 3000);@@ -588,12 +595,21 @@ async function pollGoCardlessWebToken({}return new Promise(resolve => {- getData((error, data) => {- if (error) {- resolve({ error });- } else {- resolve({ data });+ getData(data => {+ if (data.status === 'success') {+ resolve({ data: data.data });+ return;+ }++ if (data.status === 'timeout') {+ resolve({ error: data.status });+ return;}++ resolve({+ error: data.status,+ message: data.message,+ });});});}diff --git a/upcoming-release-notes/4756.md b/upcoming-release-notes/4756.mdnew file mode 100644index 0000000000..68eb2cac15--- /dev/null+++ b/upcoming-release-notes/4756.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [MatissJanis]+---++Gocardless bank sync: improved error handling for initial account linking.