@azteam/error
Advanced tools
Comparing version 1.0.19 to 1.0.20
{ | ||
"name": "@azteam/error", | ||
"version": "1.0.19", | ||
"version": "1.0.20", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
module.exports = Object.freeze({ | ||
CORS: 'CORS', | ||
NOT_FOUND: 'NOT_FOUND', | ||
@@ -3,0 +4,0 @@ UNKNOWN: 'UNKNOWN', |
const {NOT_FOUND, NOT_NULL, UNIQUE, UNKNOWN} = require('./code'); | ||
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}); | ||
} | ||
function errorCatch(e) { | ||
let status = 400; | ||
let errors = []; | ||
const errors = []; | ||
@@ -30,3 +21,3 @@ if (e.name !== undefined) { | ||
} else if (e.name === 'SequelizeValidationError') { | ||
for (let item of e.errors) { | ||
for (const item of e.errors) { | ||
if (item.message.includes('cannot be null')) { | ||
@@ -75,2 +66,11 @@ item.message = NOT_NULL; | ||
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 = { | ||
@@ -77,0 +77,0 @@ httpErrorHandler, |
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
4509
129