New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-code-error

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-code-error - npm Package Compare versions

Comparing version 0.1.31 to 0.1.32

httpStatusCode.json

14

index.js

@@ -18,3 +18,3 @@ 'use strict'

Errors.extend = function (name, status, baseCode, customCode) {
Errors.extend = function (name, status, baseCode, customCode, message) {
if (!name || !util.isNumberLike(baseCode)) {

@@ -36,2 +36,3 @@ return null

if (customCode !== undefined) this._customCode = customCode
if (message !== undefined) this.message = message
}

@@ -83,3 +84,7 @@ this._eMap[name] = Ctor

if (arguments.length === 1) {
return Err
if (util.isNumberLike(type)) {
return new Err()
} else {
return Err
}
} else {

@@ -97,1 +102,6 @@ code = Errors.ensureCode(code)

})
var statusCodeMap = require('./httpStatusCode.json')
Object.keys(statusCodeMap).sort().forEach(function (key, ind) {
Errors.extend(key, +key, 100, 10 + ind, statusCodeMap[key])
})

2

package.json
{
"name": "node-code-error",
"version": "0.1.31",
"version": "0.1.32",
"description": "define node error with code",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -5,6 +5,15 @@ 'use strict'

var CodeError = require('../index')
var Errors = CodeError.Errors
var webHttpStatus = require('../httpStatusCode.json')
it('httpStatus', function () {
Object.keys(webHttpStatus).forEach(function (key) {
var err = CodeError(key)
assert(err.toJSON().code)
assert(err.toString())
assert(err.status === +key)
})
})
it('extend', function () {
Errors.extend('internal', 500, 101, 0)
CodeError.extend('internal', 500, 101, 0)
var err = CodeError('internal', 'this is a internal error with default code')

@@ -14,3 +23,3 @@ assert(err.code === 1010)

assert(err.toJSON().type === 'InternalError')
Errors.extend('api', 400, 104)
CodeError.extend('api', 400, 104)
err = CodeError('api', 'this is a internal error without default code', 62)

@@ -24,3 +33,3 @@ assert(err.code === 10462)

// use keywords to define code
Errors.configure({
CodeError.configure({
maps: [{

@@ -41,3 +50,3 @@ user: 1,

// use msg for code
Errors.configure({
CodeError.configure({
useMsgForCode: true

@@ -50,3 +59,3 @@ })

// config split letter
Errors.configure({
CodeError.configure({
splitLetter: ',',

@@ -53,0 +62,0 @@ useMsgForCode: false

@@ -21,2 +21,3 @@ 'use strict'

assert(str && typeof str === 'string')
if (util.isNumberLike(str)) return 'Error'
return str.charAt(0).toUpperCase() + str.slice(1) + 'Error'

@@ -23,0 +24,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc