A local-first personal finance app
Stop server crashing when SimpleFIN is down. (#410)
Robert Dyer12f4295932ef
diff --git a/src/app-simplefin/app-simplefin.js b/src/app-simplefin/app-simplefin.jsindex 5d8693ebf4..31d10439c3 100644--- a/src/app-simplefin/app-simplefin.js+++ b/src/app-simplefin/app-simplefin.js@@ -50,14 +50,19 @@ app.post(const startDate = new Date(now.getFullYear(), now.getMonth(), 1);const endDate = new Date(now.getFullYear(), now.getMonth() + 1, 1);- const accounts = await getAccounts(accessKey, startDate, endDate);+ try {+ const accounts = await getAccounts(accessKey, startDate, endDate);- res.send({- status: 'ok',- data: {- accounts: accounts.accounts,- },- });+ res.send({+ status: 'ok',+ data: {+ accounts: accounts.accounts,+ },+ });+ } catch (e) {+ serverDown(e, res);+ return;+ }}),);@@ -73,9 +78,15 @@ app.post(return;}+ let results;try {- const results = await getTransactions(accessKey, new Date(startDate));+ results = await getTransactions(accessKey, new Date(startDate));+ } catch (e) {+ serverDown(e, res);+ return;+ }+ try {const account = results.accounts.find((a) => a.id === accountId);const needsAttention = results.errors.find(@@ -194,6 +205,19 @@ function invalidToken(res) {});}+function serverDown(e, res) {+ console.log(e);+ res.send({+ status: 'ok',+ data: {+ error_type: 'SERVER_DOWN',+ error_code: 'SERVER_DOWN',+ status: 'rejected',+ reason: 'There was an error communciating with SimpleFIN.',+ },+ });+}+function parseAccessKey(accessKey) {let scheme = null;let rest = null;diff --git a/upcoming-release-notes/410.md b/upcoming-release-notes/410.mdnew file mode 100644index 0000000000..4896a59dc9--- /dev/null+++ b/upcoming-release-notes/410.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [psybers]+---++Stop server crashing when SimpleFIN is down.