From b74f0f2982730f0ef24690e4b8d0d784fd7184fb Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Thu, 8 Aug 2024 14:26:36 -0500 Subject: [PATCH] Show better error if SimpleFIN account cant be found. (#412) --- src/app-simplefin/app-simplefin.js | 22 +++++++++++++++++++++- upcoming-release-notes/412.md | 6 ++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 upcoming-release-notes/412.md diff --git a/src/app-simplefin/app-simplefin.js b/src/app-simplefin/app-simplefin.js index 31d10439c..dd37ee8c5 100644 --- a/src/app-simplefin/app-simplefin.js +++ b/src/app-simplefin/app-simplefin.js @@ -87,7 +87,27 @@ app.post( } try { - const account = results.accounts.find((a) => a.id === accountId); + const account = + !results?.accounts || results.accounts.find((a) => a.id === accountId); + if (!account) { + console.log( + `The account "${accountId}" was not found. Here were the accounts returned:`, + ); + if (results?.accounts) + results.accounts.forEach((a) => + console.log(`${a.id} - ${a.org.name}`), + ); + res.send({ + status: 'ok', + data: { + error_type: 'ACCOUNT_MISSING', + error_code: 'ACCOUNT_MISSING', + status: 'rejected', + reason: `The account "${accountId}" was not found. Try unlinking and relinking the account.`, + }, + }); + return; + } const needsAttention = results.errors.find( (e) => e === `Connection to ${account.org.name} may need attention`, diff --git a/upcoming-release-notes/412.md b/upcoming-release-notes/412.md new file mode 100644 index 000000000..b8c2f4a58 --- /dev/null +++ b/upcoming-release-notes/412.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [psybers] +--- + +Show better error if SimpleFIN account cant be found.