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:
+5
-2
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user