Skip to content

Commit

Permalink
fix: Don't crash service if there is no database
Browse files Browse the repository at this point in the history
Now, each errors are thrown... So if there is no database
because there is no bills for instance, the service was crashing.

So I took this commit 7a8a8a3 and test if the error is because there is no database before throwing.
  • Loading branch information
Crash-- committed Jan 25, 2024
1 parent 06b8411 commit 8a3f9c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
21 changes: 16 additions & 5 deletions src/targets/services/onOperationOrBillCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,22 @@ const onOperationOrBillCreate = async (client, options) => {
// may be missed by `TransactionGreater` because their `_rev` don't start with `1`
const notifLastSeq = setting.notifications.lastSeq
log('info', '⌛ Fetching transaction changes...')
const notifChanges = await fetchChangesOrAll(
client,
TRANSACTION_DOCTYPE,
notifLastSeq
)
let notifChanges
try {
notifChanges = await fetchChangesOrAll(
client,
TRANSACTION_DOCTYPE,
notifLastSeq
)
} catch (e) {
if (!/Database does not exist/.test(e)) {
throw e
} else {
log('info', 'No transaction database so early exit')
process.exit(0)
}
}

log('info', '✅ Transaction changes fetched')
const brands = await makeBrands(client, undefined, true)

Expand Down
16 changes: 12 additions & 4 deletions src/targets/services/onOperationOrBillCreateHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ export const doBillsMatching = async (
logResult(result)
}
} catch (e) {
log('error', `❗ [Bills matching service] ${e}`)
throw e
if (!/Database does not exist/.test(e)) {
log('error', `❗ [Bills matching service] ${e}`)
throw e
} else {
log('info', `⚠️ [Bills matching no database]`)
}
}
}

Expand Down Expand Up @@ -104,8 +108,12 @@ export const doTransactionsMatching = async (
logResult(result)
}
} catch (e) {
log('error', `❗ [Transactions matching service] ${e}`)
throw e
if (!/Database does not exist/.test(e)) {
log('error', `❗ [Transactions matching service] ${e}`)
throw e
} else {
log('info', `⚠️ [Transactions matching service no database]`)
}
}
}

Expand Down

0 comments on commit 8a3f9c3

Please sign in to comment.