@azteam/error
Advanced tools
Comparing version 1.0.21 to 1.0.22
{ | ||
"name": "@azteam/error", | ||
"version": "1.0.21", | ||
"version": "1.0.22", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -1,2 +0,2 @@ | ||
const {NOT_FOUND, NOT_NULL, UNIQUE, UNKNOWN} = require('./code'); | ||
const {NOT_FOUND, VALIDATE, UNIQUE, UNKNOWN} = require('./code'); | ||
@@ -8,32 +8,8 @@ function errorCatch(e) { | ||
if (e.name !== undefined) { | ||
if (e.name === 'SequelizeValidationError' || e.name === 'SequelizeUniqueConstraintError') { | ||
if (e.name === 'SequelizeUniqueConstraintError') { | ||
for (let item of e.errors) { | ||
errors.push({ | ||
code: UNIQUE, | ||
message: UNIQUE, | ||
data: { | ||
field: item.path.replace('UNI_', ''), | ||
value: item.value, | ||
}, | ||
}); | ||
} | ||
} else if (e.name === 'SequelizeValidationError') { | ||
for (const item of e.errors) { | ||
if (item.message.includes('cannot be null')) { | ||
item.message = NOT_NULL; | ||
} | ||
errors.push({ | ||
code: item.message, | ||
message: item.message, | ||
data: { | ||
field: item.path, | ||
value: item.value, | ||
}, | ||
}); | ||
} | ||
} | ||
} else if (e.name === 'ErrorException') { | ||
if (e.name === 'ErrorException') { | ||
let fields = []; | ||
if (e.code === NOT_FOUND) { | ||
status = 404; | ||
} else if (e.code === VALIDATE) { | ||
fields = e.errors.map((obj) => obj.field); | ||
} | ||
@@ -44,2 +20,3 @@ errors.push({ | ||
data: e.errors, | ||
fields: fields.join(','), | ||
}); | ||
@@ -57,2 +34,3 @@ } else if (e.name === 'MulterError') { | ||
data: e.keyValue, | ||
fields: Object.keys(e.keyValue).join(','), | ||
}); | ||
@@ -76,14 +54,4 @@ } | ||
function httpErrorHandler(e, req, res, next) { | ||
const error = errorCatch(e); | ||
if (process.env.NODE_ENV === 'development') { | ||
console.log(error.errors); | ||
} | ||
return res.status(error.status).json({success: false, errors: error.errors}); | ||
} | ||
module.exports = { | ||
httpErrorHandler, | ||
errorCatch, | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1
3606
107