@darkwolf/code-error
Advanced tools
Comparing version 2.0.1 to 2.0.2
19
index.js
@@ -0,1 +1,3 @@ | ||
const State = require('@darkwolf/state') | ||
class CodeError extends Error { | ||
@@ -12,2 +14,3 @@ constructor(...args) { | ||
this.namespace = namespace | ||
this.space = namespace | ||
this.code = code | ||
@@ -22,19 +25,9 @@ this.message = message | ||
} | ||
} | ||
setData(data) { | ||
this.data = data | ||
return this | ||
const {state, setState} = new State() | ||
this.state = state | ||
this.setState = setState | ||
} | ||
updateData(callback) { | ||
return this.setData(callback(this.data)) | ||
} | ||
deleteData() { | ||
this.data = undefined | ||
return this | ||
} | ||
} | ||
module.exports = CodeError |
{ | ||
"name": "@darkwolf/code-error", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Code Error Utility", | ||
@@ -24,3 +24,6 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://github.com/darkwolf/code-error#readme" | ||
"homepage": "https://github.com/darkwolf/code-error#readme", | ||
"dependencies": { | ||
"@darkwolf/state": "^1.0.0" | ||
} | ||
} |
@@ -11,5 +11,3 @@ # Code Error Utility | ||
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) | ||
const SPACE_CODE_ERROR = new CodeError(namespace, code, message) | ||
@@ -19,5 +17,14 @@ try { | ||
} catch (e) { | ||
switch (e.code) { | ||
case code: | ||
doSmth() | ||
switch (e.space) { | ||
case 'namespace': { | ||
switch (e.code) { | ||
case 'invalid-code': { | ||
doSmth() | ||
break | ||
} | ||
default: throw e | ||
} | ||
break | ||
} | ||
default: throw e | ||
} | ||
@@ -29,4 +36,2 @@ } | ||
## Methods | ||
### setData(data) | ||
### updateData(data => newData) | ||
### deleteData() | ||
### setState(newState || callbac(state => newState)) |
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
3128
35
1
26
+ Added@darkwolf/state@^1.0.0