Centralize and standardize database error handling

Introduced a new handleDBError utility in modules/utils.js to centralize database error logging and throwing. Refactored all repositories to use this utility, replacing repetitive error handling and logger calls with a single function call for improved maintainability and consistency.
This commit is contained in:
2026-01-18 18:04:10 +01:00
parent 88f8ee57e1
commit 71627c7041
7 changed files with 91 additions and 183 deletions
+5 -2
View File
@@ -1,11 +1,14 @@
const fs = require("node:fs")
const path = require("node:path")
const utils = require("./utils")
require("colors")
require("dotenv").config({
quiet: true
})
function isTrueFromDotEnv(key) {
return (process.env[key] || "").trim().toLowerCase() === "true"
}
function cleanup($stream) {
if (!$stream.destroyed) {
$stream.end()
@@ -41,7 +44,7 @@ function write($stream, level, color, content, extraLabels = []) {
function createLogger(root) {
// eslint-disable-next-line no-useless-escape
const fileName = utils.isTrueFromDotEnv("IS_PROD") ? new Date().toLocaleString("fr-FR", { timeZone: "UTC" }).replace(/[\/:]/g, "-").replace(/ /g, "_") : "DEV-LOG"
const fileName = isTrueFromDotEnv("IS_PROD") ? new Date().toLocaleString("fr-FR", { timeZone: "UTC" }).replace(/[\/:]/g, "-").replace(/ /g, "_") : "DEV-LOG"
const logsDir = path.join(root, "logs")