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