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
+8
View File
@@ -1,4 +1,6 @@
const crypto = require("node:crypto")
const logger = require("../modules/logger")
const { DefaultError } = require("../errors/errors")
const certificatesManager = require("./certificatesManager")
async function getRegistrationCountryFromIp(ipAddress) {
@@ -60,8 +62,14 @@ function getUrlParam(url, param) {
return urlParams.get(param)
}
function handleDBError(error, errorMessage = "Internal Server Error", code = 500) {
logger.log(errorMessage.bold + " : " + error.toString(), ["MariaDB", "yellow"])
throw new DefaultError(code, errorMessage, "InternalServerError")
}
module.exports = {
getUrlParam,
handleDBError,
signProfileData,
addDashesToUUID,
isTrueFromDotEnv,