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.36 to 0.1.41

i18n.js

13

error.js
'use strict'
var util = require('./util')
var __ = require('./i18n').__
module.exports = CodeError

@@ -19,2 +20,3 @@

return {
status: this.status,
code: this.code,

@@ -26,2 +28,13 @@ message: this.message,

CodeError.prototype.toLocaleJSON = function (opts, data) {
opts = opts || {}
opts.status = opts.status || this.status
opts.code = opts.code || this.code
var localed = __(opts, data)
localed.code = this.code
localed.type = this.name
localed.status = this.status
return localed
}
Object.defineProperty(CodeError.prototype, 'code', {

@@ -28,0 +41,0 @@ get: function () {

'use strict'
var CodeError = require('./error')
var util = require('./util')
var i18n = require('./i18n')

@@ -44,2 +45,8 @@ var Errors = {

if (opts.splitLetter) this._split = opts.splitLetter
if (opts.i18n || opts.additionKeys) {
i18n.configure({
i18n: opts.i18n,
additionKeys: opts.additionKeys
})
}
this._useMsgCode = !!opts.useMsgForCode

@@ -46,0 +53,0 @@ }

3

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

@@ -22,2 +22,3 @@ "main": "./index.js",

"dependencies": {
"i18n": "^0.8.1"
},

@@ -24,0 +25,0 @@ "devDependencies": {

@@ -63,2 +63,17 @@ 'use strict'

assert(err.toJSON().type === 'ApiError')
// config additionKeys
CodeError.configure({
additionKeys: ['action', 'refer'],
i18n: {
locales: ['en', 'zh'],
defaultLocale: 'zh',
directory: __dirname + '/../test_locales'
}
})
err = CodeError('api', 'invalid user in xx api', 11)
var localeJson = err.toLocaleJSON({action: 'create', refer: 'github'})
assert(localeJson.message === '创建Github账户失败')
assert(localeJson.title === 400)
localeJson = err.toLocaleJSON({action: 'edit', refer: 'github'})
assert(localeJson.message === '错误的请求')
})
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