common-errors
Advanced tools
Comparing version
@@ -19,2 +19,3 @@ var util = require('util'); | ||
exports.HttpStatusError = exports.HttpStatus = require('./lib/http-status'); | ||
exports.NotFoundError = require('./lib/not-found'); | ||
exports.NotImplementedError = exports.helpers.generateClass('NotImplementedError'), | ||
@@ -77,3 +78,3 @@ exports.NotSupportedError = exports.NotSupported = require('./lib/not-supported'); | ||
var stackToPrepend = (new Error()).stack.split("\n").slice(linesToSkip); | ||
var mainStack = err.stack.split("\n"); | ||
var mainStack = (err.stack || '').split("\n"); | ||
var errTitle = mainStack.shift(); | ||
@@ -80,0 +81,0 @@ err.stack = [errTitle].concat(stackToPrepend, "====", mainStack).join("\n"); |
@@ -49,2 +49,3 @@ var util = require('util'); | ||
}, | ||
"NotFoundError": 404, | ||
"NotSupportedError": 405, | ||
@@ -51,0 +52,0 @@ "AlreadyInUseError": 409, |
@@ -5,3 +5,3 @@ { | ||
"description": "Common error classes and utility functions", | ||
"version": "0.4.7", | ||
"version": "0.4.8", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -29,2 +29,3 @@ common-errors | ||
* [FileNotFoundError](#filenotfound) | ||
* [NotFoundError](#notfound) | ||
* [NotImplementedError](#notimplemented) | ||
@@ -301,2 +302,21 @@ * [NotPermittedError](#notpermitted) | ||
<a name="notfound" /> | ||
### NotFoundError | ||
Applicable when an attempt to retrieve data yielded no result. | ||
new NotFoundError(entity_name[, inner_error]) | ||
__Arguments__ | ||
* `entity_name` - a description for what was not found | ||
* `inner_error` - the Error instance that caused the current error. Stack trace will be appended. | ||
```js | ||
// Example | ||
throw new errors.NotFoundError("User", err) | ||
``` | ||
--------------------------------------- | ||
<a name="notimplemented" /> | ||
@@ -303,0 +323,0 @@ ### NotImplementedError |
@@ -80,2 +80,10 @@ var assert = require('assert'); | ||
it("should handle NotFoundError", function(){ | ||
var res = new Response(); | ||
errorHandler(new errors.NotFoundError("test"), {}, res); | ||
assert.equal(res.status_code, 404); | ||
assert.equal(res.message, "Not Found: \"test\""); | ||
assert.ok(!console.error.called); | ||
}); | ||
it("should handle Error", function(){ | ||
@@ -82,0 +90,0 @@ var res = new Response(); |
50694
1.25%666
0.45%672
3.07%