node-http-error
Advanced tools
Comparing version 0.2.0 to 1.0.0
@@ -7,3 +7,3 @@ var util = require('util'); | ||
var HTTPError = module.exports = function HTTPError(status, message) { | ||
var HTTPError = module.exports = function HTTPError(status, message, properties) { | ||
// Make sure we're using the 'new' keyword | ||
@@ -31,2 +31,3 @@ if (!(this instanceof HTTPError)) return new HTTPError(status, message); | ||
this.message = message || ''; | ||
util._extend(this, properties); | ||
}; | ||
@@ -33,0 +34,0 @@ |
{ | ||
"name": "node-http-error", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "Error subclasses for returning HTTP errors", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,3 +21,3 @@ # Pretty HTTP Errors for Node | ||
app.use(function(err, req, res, next) { | ||
res.status(err.code); | ||
res.status(err.status); | ||
res.send(err.message); | ||
@@ -48,5 +48,11 @@ }); | ||
- Give it just the HTTP status code you want to return, and the error message is automatically generated. | ||
- Assign extra properties to the error. | ||
## Usage | ||
#### `HTTPError(status, message, properties)` | ||
Creates an error with the given status, message and properties. For example | ||
new HTTPError(404, 'Not found!', { path: '/something-missing' }) | ||
#### `HTTPError(status, message)` | ||
@@ -53,0 +59,0 @@ Creates an error message with the given status and message. |
@@ -55,2 +55,9 @@ var HTTPError = require('../'); | ||
}); | ||
it('should allow extra error properties', function() { | ||
var err = new HTTPError(404, 'Not found!', { path: '/something-missing' }); | ||
err.should.have.property('status', 404); | ||
err.should.have.property('message', 'Not found!'); | ||
err.should.have.property('path', '/something-missing'); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
44729
119
0
66