@darkwolf/code-error
Advanced tools
Comparing version 1.0.2 to 2.0.0
31
index.js
class CodeError extends Error { | ||
constructor(code, message, data) { | ||
constructor(...args) { | ||
super() | ||
this.name = 'CodeError' | ||
this.code = code | ||
this.message = message | ||
this.data = data | ||
if (args.length <= 2) { | ||
const [code, message] = args | ||
this.code = code | ||
this.message = message | ||
} else { | ||
const [namespace, code, message] = args | ||
this.namespace = namespace | ||
this.code = code | ||
this.message = message | ||
} | ||
if (Error.captureStackTrace) { | ||
@@ -15,4 +22,18 @@ Error.captureStackTrace(this, CodeError) | ||
} | ||
setData(data) { | ||
this.data = data | ||
return this | ||
} | ||
updateData(callback) { | ||
return this.setData(callback(this.data)) | ||
} | ||
deleteData() { | ||
this.data = undefined | ||
return this | ||
} | ||
} | ||
module.exports = CodeError |
{ | ||
"name": "@darkwolf/code-error", | ||
"version": "1.0.2", | ||
"description": "CodeError", | ||
"version": "2.0.0", | ||
"description": "Code Error Utility", | ||
"main": "index.js", | ||
@@ -15,3 +15,5 @@ "scripts": { | ||
"code", | ||
"error" | ||
"error", | ||
"utility", | ||
"utils" | ||
], | ||
@@ -18,0 +20,0 @@ "author": "Pavel Wolf", |
@@ -1,10 +0,14 @@ | ||
# Code Error | ||
# Code Error Utility | ||
## Install | ||
```sh | ||
npm i --save @darkwolf/code-error | ||
``` | ||
## Use | ||
## Usage | ||
```javascript | ||
const CodeError = require('@darkwolf/code-error') | ||
const CODE_ERROR = new CodeError(code, message, data) | ||
const CODE_ERROR = new CodeError(code, message) | ||
const NAMESPACE_CODE_ERROR = new CodeError(namespace, code, message) | ||
const DATA_CODE_ERROR = new CodeError(code, message).setData(data) | ||
const DATA_NAMESPACE_CODE_ERROR = new CodeError(namespace, code, message).setData(data) | ||
@@ -16,3 +20,2 @@ try { | ||
case code: | ||
const data = e.data | ||
doSmth() | ||
@@ -22,1 +25,7 @@ } | ||
``` | ||
## Initialization | ||
### new CodeError(namespace?, code, message) | ||
## Methods | ||
### setData(data) | ||
### setUpdate(update => newUpdate) | ||
### deleteData() |
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
3120
5
32
30