More graceful track-investments if SimpleFIN is down.
This commit is contained in:
@@ -38,6 +38,7 @@ const getSimplefinBalances = async () => {
|
||||
const username = credentials.split(':')[0];
|
||||
const pw = credentials.split(':')[1];
|
||||
|
||||
try {
|
||||
const url = `https://beta-bridge.simplefin.org/simplefin/accounts?start-date=${new Date().getTime()}&end-date=${new Date().getTime()}`;
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
@@ -48,6 +49,9 @@ const getSimplefinBalances = async () => {
|
||||
const accounts = data.accounts;
|
||||
const balances = {};
|
||||
accounts.forEach(a => balances[a.name] = parseFloat(a.balance));
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
return balances;
|
||||
};
|
||||
|
||||
@@ -71,7 +75,7 @@ const zeroTransaction = async (payment) => {
|
||||
const categoryId = await ensureCategory(process.env.IMPORTER_INVESTMENT_CATEGORY_NAME || 'Investment');
|
||||
|
||||
const simplefinBalances = await getSimplefinBalances();
|
||||
|
||||
if (simplefinBalances) {
|
||||
const accounts = await api.getAccounts();
|
||||
for (const account of accounts) {
|
||||
if (account.closed) {
|
||||
@@ -125,6 +129,7 @@ const zeroTransaction = async (payment) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await closeBudget();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user