Socket
Socket
Sign inDemoInstall

node-http-error

Package Overview
Dependencies
0
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 1.0.0

3

index.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc