error-handler-e2
Advanced tools
Comparing version 1.1.1 to 2.0.0
63
index.js
@@ -1,20 +0,55 @@ | ||
const error = (message, status) => { | ||
let error_type; | ||
if (status >= 400 && status < 500) { | ||
error_type = "Client Error."; | ||
} else if(status >= 500 && status < 600){ | ||
error_type = " Server Error."; | ||
} else{ | ||
error_type = `${status}, it should not be a error status code`; | ||
/** | ||
* @author Milad E. Fahmy | ||
* @param {String} colorName | ||
* @description colorName cane be on of the following Bright, Dim, Underscore, | ||
* FgBlack, FgRed, FgGreen, FgYellow, FgBlue, FgMagenta, FgCyan, FgWhite | ||
*/ | ||
const getColor = (colorName) => { | ||
const colors = { | ||
Bright: "\x1b[1m", | ||
Dim: "\x1b[2m", | ||
Underscore: "\x1b[4m", | ||
FgBlack: "\x1b[30m", | ||
FgRed: "\x1b[31m", | ||
FgGreen: "\x1b[32m", | ||
FgYellow: "\x1b[33m", | ||
FgBlue: "\x1b[34m", | ||
FgMagenta: "\x1b[35m", | ||
FgCyan: "\x1b[36m", | ||
FgWhite: "\x1b[37m", | ||
} | ||
return colors[colorName]; | ||
} | ||
/** | ||
* @author Milad E. Fahmy | ||
* @param {Object} error | ||
* @description this a function to custom log errors | ||
*/ | ||
const logErrors = ({ type, file, path, message, status, ...restArgs }) => { | ||
return { | ||
message, | ||
status, | ||
error_type, | ||
}; | ||
console.group(getColor("FgRed"), `Error: ${type.toUpperCase()}`) | ||
console.log(getColor("FgGreen"), "*** Start Logging Error ***\n"); | ||
console.log(getColor("FgBlue"), `The error in File : ${file}`); | ||
console.log(getColor("FgBlue"), `The error with status code : ${status}`); | ||
console.log(getColor("FgBlue"), `The error in path : ${path}`); | ||
console.log(getColor("FgBlue"), `Custom message :${message}\n`); | ||
let restErrors = Object.keys(restArgs) | ||
for (let index = 0; index < restErrors.length; index++) { | ||
const key = restErrors[index]; | ||
console.group(getColor("FgCyan"), `Related Errors: `); | ||
console.log(getColor("FgYellow"), `${key.toUpperCase()} => ${restArgs[key]}`); | ||
} | ||
console.groupEnd(); | ||
console.log("\n") | ||
console.log(getColor("FgGreen"), "*** End Logging Error ***"); | ||
console.groupEnd(); | ||
} | ||
module.exports = { | ||
error | ||
getColor, | ||
logErrors | ||
} |
{ | ||
"name": "error-handler-e2", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "This is handle error package", | ||
@@ -8,3 +8,18 @@ "main": "index.js", | ||
"author": "Milad E. Fahmy", | ||
"license": "ISC" | ||
"license": "ISC", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/miladezzat/error-handler-e2.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/miladezzat/error-handler-e2/issues" | ||
}, | ||
"homepage": "https://github.com/miladezzat/error-handler-e2#readme", | ||
"keywords": [ | ||
"Errors", | ||
"error", | ||
"error-handler", | ||
"expressjs", | ||
"nodejs" | ||
] | ||
} |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
2332
48
0
0
0