Skip to content

A local-first personal finance app

Fix issue where the UI is stuck sync'ing if no data from server (#3941)

Robert Dyere6aeea668bd8
diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts
index 42ff79b628..62954778ca 100644
--- a/packages/loot-core/src/server/accounts/sync.ts
+++ b/packages/loot-core/src/server/accounts/sync.ts
@@ -205,6 +205,9 @@ async function downloadSimpleFinTransactions(
60000,
);
+ if (Object.keys(res).length === 0) {
+ throw BankSyncError('NO_DATA', 'NO_DATA');
+ }
if (res.error_code) {
throw BankSyncError(res.error_type, res.error_code);
}
diff --git a/packages/loot-core/src/server/main.ts b/packages/loot-core/src/server/main.ts
index efeafaf621..f4ee2c7b69 100644
--- a/packages/loot-core/src/server/main.ts
+++ b/packages/loot-core/src/server/main.ts
@@ -1168,46 +1168,62 @@ handlers['simplefin-batch-sync'] = async function ({ ids = [] }) {
true,
);
+ const retVal = [];
+
console.group('Bank Sync operation for all SimpleFin accounts');
- const res = await bankSync.SimpleFinBatchSync(
- accounts.map(a => ({
- id: a.id,
- accountId: a.account_id,
- })),
- );
+ try {
+ const res = await bankSync.SimpleFinBatchSync(
+ accounts.map(a => ({
+ id: a.id,
+ accountId: a.account_id,
+ })),
+ );
+ for (const account of res) {
+ const errors = [];
+ const newTransactions = [];
+ const matchedTransactions = [];
+ const updatedAccounts = [];
+
+ if (account.res.error_code) {
+ errors.push(
+ handleSyncError(
+ {
+ type: 'BankSyncError',
+ category: account.res.error_type,
+ code: account.res.error_code,
+ },
+ accounts.find(a => a.id === account.accountId),
+ ),
+ );
+ } else {
+ handleSyncResponse(
+ account.res,
+ accounts.find(a => a.id === account.accountId),
+ newTransactions,
+ matchedTransactions,
+ updatedAccounts,
+ );
+ }
- const retVal = [];
- for (const account of res) {
+ retVal.push({
+ accountId: account.accountId,
+ res: { errors, newTransactions, matchedTransactions, updatedAccounts },
+ });
+ }
+ } catch (err) {
const errors = [];
- const newTransactions = [];
- const matchedTransactions = [];
- const updatedAccounts = [];
-
- if (account.res.error_code) {
- errors.push(
- handleSyncError(
- {
- type: 'BankSyncError',
- category: account.res.error_type,
- code: account.res.error_code,
- },
- accounts.find(a => a.id === account.accountId),
- ),
- );
- } else {
- handleSyncResponse(
- account.res,
- accounts.find(a => a.id === account.accountId),
- newTransactions,
- matchedTransactions,
- updatedAccounts,
- );
+ for (const account of accounts) {
+ retVal.push({
+ accountId: account.accountId,
+ res: {
+ errors,
+ newTransactions: [],
+ matchedTransactions: [],
+ updatedAccounts: [],
+ },
+ });
+ errors.push(handleSyncError(err, account));
}
-
- retVal.push({
- accountId: account.accountId,
- res: { errors, newTransactions, matchedTransactions, updatedAccounts },
- });
}
if (retVal.some(a => a.res.updatedAccounts.length > 0)) {
diff --git a/upcoming-release-notes/3941.md b/upcoming-release-notes/3941.md
new file mode 100644
index 0000000000..2e57738f0d
--- /dev/null
+++ b/upcoming-release-notes/3941.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [psybers]
+---
+
+Fix UI issue with bank sync being stuck if no data from server.