error-provider
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -65,3 +65,3 @@ "use strict"; | ||
var codes = { | ||
errors._codes = { | ||
"-1": "UNKNOWN", | ||
@@ -141,10 +141,6 @@ "0": "OK", | ||
errors[code] = e; | ||
codes[errno] = code; | ||
this[code] = e; | ||
this._codes[errno] = code; | ||
}; | ||
var replace = function (s, k, v){ | ||
return s.replace (new RegExp ("\\{" + k + "\\}", "g"), v); | ||
}; | ||
errors.get = function (id, vars){ | ||
@@ -155,5 +151,5 @@ var error; | ||
if (type === "number"){ | ||
error = errors[codes[id]]; | ||
error = this[this._codes[id]]; | ||
}else if (type === "string"){ | ||
error = errors[id]; | ||
error = this[id]; | ||
}else{ | ||
@@ -189,8 +185,15 @@ error = id; | ||
var next = 100; | ||
errors.local = function (){ | ||
return { | ||
create: errors.create, | ||
get: errors.get, | ||
next: errors.next, | ||
_next: 0, | ||
_codes: {} | ||
}; | ||
}; | ||
errors._next = 100; | ||
errors.next = function (){ | ||
var n = next; | ||
next++; | ||
return n; | ||
return this._next++; | ||
}; |
{ | ||
"name": "error-provider", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Manages errors for third-party modules", | ||
@@ -5,0 +5,0 @@ "keywords": ["error", "errno", "provider", "libuv"], |
@@ -8,3 +8,3 @@ error-provider | ||
Version: 0.0.2 | ||
Version: 0.0.3 | ||
@@ -93,2 +93,10 @@ When you're writing a third-party module you'll probably deal with errors. If you want to send custom errors to your users you should send a code and then in your documentation explain these codes. | ||
There's a special method called `local()` that returns a local error provider. If you need a local storage with custom errors that you don't need to make public, `local()` can help you. If another third-party module uses the `error-provider` module you won't see its errors, the local error provider is local to your module. The first available errno is 0 and the set of default codes is empty, that is, you can't return a built-in error like `EEXIST`. You can create all the storages you want. | ||
```javascript | ||
var ep = require ("error-provider").local (); | ||
ep.create (ep.next (), ...); | ||
ep.get (...); | ||
``` | ||
- [ep.create(errno, code, description[, properties])](#create) | ||
@@ -95,0 +103,0 @@ - [ep.get(id[, vars])](#get) |
12803
179
173