Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-verror

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-verror - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

.idea/inspectionProfiles/profiles_settings.xml

229

lib/index.js
/**
* @file http-verror
* @module http-verror
* @copyright Dr. Evil <dr.evil@krtn.eu> - 21/11/2014

@@ -12,13 +13,211 @@ */

var httpErrors = {
400: { name: 'BadRequest', description: 'Invalid data was sent to the server' },
401: { name: 'Unauthenticated', description: 'You\'re not authorized to perform such action' },
403: { name: 'Forbidden', description: 'You\'re not allowed to perform such action' },
404: { name: 'NotFound', description: 'Resource was not found' },
409: { name: 'Conflict', description: 'Item exists or dependency absent' },
500: { name: 'InternalError', description: 'Unexpected internal error' },
502: { name: 'BadGateway', description: 'Bad gateway' },
503: { name: 'Unavailable', description: 'Not available' },
504: { name: 'GatewayTimeout', description: 'Gateway time-out' }
/**
* HTTP status code 400
*
* @constructor
* @name BadRequest
* @memberOf errors
*/
400: {
name: 'BadRequest',
description: 'Invalid data was sent to the server'
},
/**
* HTTP status code 401
*
* @constructor
* @name Unauthorized
* @memberOf errors
*/
401: {
name: 'Unauthorized',
description: 'You\'re not authorized to perform such action'
},
/**
* HTTP status code 402
*
* @constructor
* @name PaymentRequired
* @memberOf errors
*/
402: {
name: 'PaymentRequired',
description: ''
},
/**
* HTTP status code 403
*
* @static
* @name Forbidden
* @memberOf errors
*/
403: {
name: 'Forbidden',
description: 'You\'re not allowed to perform such action'
},
/**
* HTTP status code 404
*
* @constructor
* @name NotFound
* @memberOf errors
*/
404: {
name: 'NotFound',
description: 'Resource was not found'
},
/**
* HTTP status code 405
*
* @constructor
* @name MethodNotAllowed
* @memberOf errors
*/
405: {
name: 'MethodNotAllowed',
description: 'The method specified is not allowed for the requested resource'
},
/**
* HTTP status code 406
*
* @constructor
* @name NotAcceptable
* @memberOf errors
*/
406: {
name: 'NotAcceptable',
description: 'The resource identified by the request is only capable of generating response entities which' +
' have content characteristics not acceptable according to the accept headers sent in the request.'
},
/**
* HTTP status code 408
*
* @constructor
* @name RequestTimeout
* @memberOf errors
*/
408: {
name: 'RequestTimeout',
description: 'The client did not produce a request within the time that the server was prepared to wait.'
},
/**
* HTTP status code 409
*
* @constructor
* @name Conflict
* @memberOf errors
*/
409: {
name: 'Conflict',
description: 'The request could not be completed due to a conflict with the current state of the resource.'
},
/**
* HTTP status code 412
*
* @constructor
* @name PreconditionFailed
* @memberOf errors
*/
412: {
name: 'PreconditionFailed',
description: 'The precondition given in one or more of the request-header fields evaluated to false when it' +
' was tested on the server.'
},
/**
* HTTP status code 415
*
* @constructor
* @name UnsupportedMediaType
* @memberOf errors
*/
415: {
name: 'UnsupportedMediaType',
description: 'The server is refusing to service the request because the entity of the request is in a format' +
' not supported by the requested resource for the requested method.'
},
/**
* HTTP status code 500
*
* @constructor
* @name InternalError
* @memberOf errors
*/
500: {
name: 'InternalError',
description: 'The server encountered an unexpected condition which prevented it from fulfilling the request.'
},
/**
* HTTP status code 501
*
* @constructor
* @name NotImplemented
* @memberOf errors
*/
501: {
name: 'NotImplemented',
description: 'The server does not support the functionality required to fulfill the request.'
},
/**
* HTTP status code 502
*
* @constructor
* @name BadGateway
* @memberOf errors
*/
502: {
name: 'BadGateway',
description: 'The server, while acting as a gateway or proxy, received an invalid response from the upstream' +
' server it accessed in attempting to fulfill the request.'
},
/**
* HTTP status code 503
*
* @constructor
* @name ServiceUnavailable
* @memberOf errors
*/
503: {
name: 'ServiceUnavailable',
description: 'The server is currently unable to handle the request due to a temporary overloading or' +
' maintenance of the server.'
},
/**
* HTTP status code 504
*
* @constructor
* @name GatewayTimeout
* @memberOf errors
*/
504: {
name: 'GatewayTimeout',
description: 'The server did not receive a timely response from the upstream server.'
}
};
/**
* @private
* @constructor
* @name HttpError
* @augments WError
*
* @param {Number} code
*
* @returns {HttpError}
*/
function HttpError (code) {

@@ -36,2 +235,10 @@ this.statusCode = code;

/**
* @private
* @class
* @name E
* @param {Number} code HTTP status code
* @returns {HttpError}
* @constructor
*/
function E (code) {

@@ -41,2 +248,6 @@ return HttpError.bind(this, code);

/**
* @class errors
* @name errors
*/
var errors = {};

@@ -43,0 +254,0 @@

5

package.json
{
"name": "http-verror",
"version": "0.0.2",
"version": "0.0.3",
"description": "A simple tool that provides `verror` functionality extended by usable HTTP error codes for Express.js",

@@ -27,8 +27,7 @@ "main": "index.js",

"dependencies": {
"mocha-lcov-reporter": "0.0.1",
"verror": "^1.6.0"
},
"devDependencies": {
"mocha-lcov-reporter": "0.0.1",
"blanket": "^1.1.6",
"expect.js": "^0.3.1",
"mocha": "^2.0.1"

@@ -35,0 +34,0 @@ },

@@ -6,2 +6,42 @@ # http-verror - VError adaptation for usage with Express.js

## Installation
```npm install http-verror --save```
```npm install http-verror --save```
## Usage
http-verror instance inherits all properties of [WError](https://github.com/davepacheco/node-verror#werror-wrap-layered-errors). In other words, http-verror is a WError but with `statusCode` property being equal to the HTTP status code of the error you created.
### Example
```javascript
var errors = require('http-verror');
var err = new errors.Forbidden();
console.log(err.statusCode); // 403
console.log(err.message); // You're not allowed to perform such action
var err2 = new errors.InternalError(new Error('Some preceding error with internal data'), 'Brief error desc');
console.log(err2.statusCode); // 500
console.log(err2.message); // Brief error desc
console.log(err2.cause().message); // Some preceding error with internal data
console.log(err2.toString()); // HttpError: Brief error desc; caused by Error: Some preceding error with internal data
```
### Errors
| Status code | Name |
| :---------: | ---------------------- |
| 400 | BadRequest |
| 401 | Unauthorized |
| 402 | PaymentRequired |
| 403 | Forbidden |
| 404 | NotFound |
| 405 | MethodNotAllowed |
| 406 | NotAcceptable |
| 408 | RequestTimeout |
| 409 | Conflict |
| 412 | PreconditionFailed |
| 415 | UnsupportedMediaType |
| 500 | InternalError |
| 501 | NotImplemented |
| 502 | BadGateway |
| 503 | ServiceUnavailable |
| 504 | GatewayTimeout |
'use strict';
var expect = require('expect.js'),
/* jshint mocha:true */
var assert = require('assert'),
errors = require('../lib');

@@ -14,4 +16,4 @@

expect(e.statusCode).to.be.equal(400);
expect(e.message).to.be.equal('Invalid data was sent to the server');
assert.strictEqual(e.statusCode, 400);
assert.strictEqual(e.message, 'Invalid data was sent to the server');
});

@@ -22,6 +24,6 @@

expect(e.statusCode).to.be.equal(403);
expect(e.message).to.be.equal('we don\'t show that it was test error');
expect(e.cause().message).to.be.equal('test error');
assert.strictEqual(e.statusCode, 403);
assert.strictEqual(e.message, 'we don\'t show that it was test error');
assert.strictEqual(e.cause().message, 'test error');
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc