Skip to content

Commit

Permalink
Stop server crashing when SimpleFIN is down. (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
psybers authored Aug 5, 2024
1 parent d33e5cc commit 12f4295
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
40 changes: 32 additions & 8 deletions src/app-simplefin/app-simplefin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}),
);

Expand All @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/410.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [psybers]
---

Stop server crashing when SimpleFIN is down.

0 comments on commit 12f4295

Please sign in to comment.