Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
node-code-error
Advanced tools
define errror with code
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]
npm install node-code-error
// extend a new type of error
var CodeError = require('node-code-error')
CodeError.extend('api', 400, 100)
var err = CodeError('api', 'db is not defined', 32)
err.status // 400
err.toString() // 'ApiError: db is not defined'
err.toJSON()
/*
{
code: 10032,
message: 'ApiError: db is not defined',
type: 'ApiError'
}
*/
// configure CodeError and describe code by keywords
CodeError.configure({
maps: [{
user: 1,
book: 2,
cat: 3
}, {
missed: 1,
invalid: 2,
unmatched: 3
}],
splitLetter: ' ' // default is ' ',
useMsgForCode: true // default is false
})
// then you can create err like this
err = CodeError('api', 'user invalid')
err.status // 400
err.toString() // 'ApiError: user invalid'
err.toJSON()
/*
{
code: 10012,
message: 'ApiError: user invalid',
type: 'ApiError'
}
*/
var CodeError = require('node-code-error')
CodeError.extend('api', 400, 100)
CodeError('api') // => function ApiError
CodeError('api', 'api error', 32, new Error('xxx')) // => instance of ApiError
name
Required, String
, define the type of the errorstatus
Number
, define the status of the error, default is 500baseCode
Required, Number
, the first part of the codecustomCode
Option, Number
, if passed, the last part of code will be always the customCode, this is used for errors with stationary code, like SystemErrorvar CodeError = require('node-code-error')
CodeError.extend('api', 400, 100)
CodeError('api', 'api error', 43) // code == 10043
CodeError.extend('system', 500, 101, 10)
CodeError('system', 'system error', 43) // code == 10110
Array
map of values for keywords.for common use, you can use maps[0] as map of model, use maps[1] as map of action.then, your error message will like 'user invalid', 'password unmatch', etc.var CodeError = require('node-code-error')
CodeError.configure({
maps: [{
user: 1,
book: 2,
cat: 3
}, {
missed: 1,
invalid: 2,
unmatch: 3
}],
splitLetter: ' ' // default is ' ',
useMsgForCode: true // default is false
})
CodeError.extend('api', 400, 100)
var err = CodeError('api', 'use missed')
err.code // => 10011
var err = CodeError('api', 'book unmatch')
err.code // => 10023
Error
the error to be wrappedString
which type of error to wrap, default is 'system'CodeError.extend('system', 500, 100, 10)
var err = new Error("I'm a nodejs Error")
var wrapped = CodeError.wrap(err, 'system')
wrapped.toString() // => "SystemError: I'm a nodejs Error"
wrapped.toJSON()
/*
=> {
code: 10010,
message: "SystemError: I'm a nodejs Error",
type: "SystemError"
}
*/
FAQs
define node error with code
The npm package node-code-error receives a total of 1 weekly downloads. As such, node-code-error popularity was classified as not popular.
We found that node-code-error demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.