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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user