🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

httpexceptions

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

httpexceptions - npm Package Compare versions

Comparing version

to
1.2.2

lib/badgateway.ts

76

index.js

@@ -1,16 +0,17 @@

"use strict";
var exception_1 = require("./lib/exception");
var badgateway_1 = require("./lib/types/badgateway");
var badrequest_1 = require("./lib/types/badrequest");
var forbidden_1 = require("./lib/types/forbidden");
var gatewaytimeout_1 = require("./lib/types/gatewaytimeout");
var internalservererror_1 = require("./lib/types/internalservererror");
var methodnotallowed_1 = require("./lib/types/methodnotallowed");
var notacceptable_1 = require("./lib/types/notacceptable");
var notfound_1 = require("./lib/types/notfound");
var notimplemented_1 = require("./lib/types/notimplemented");
var paymentrequired_1 = require("./lib/types/paymentrequired");
var proxyerror_1 = require("./lib/types/proxyerror");
var serviceunvailable_1 = require("./lib/types/serviceunvailable");
var unauthorized_1 = require("./lib/types/unauthorized");
var badgateway_1 = require("./lib/badgateway");
var badrequest_1 = require("./lib/badrequest");
var forbidden_1 = require("./lib/forbidden");
var gatewaytimeout_1 = require("./lib/gatewaytimeout");
var internalservererror_1 = require("./lib/internalservererror");
var methodnotallowed_1 = require("./lib/methodnotallowed");
var notacceptable_1 = require("./lib/notacceptable");
var notfound_1 = require("./lib/notfound");
var notimplemented_1 = require("./lib/notimplemented");
var paymentrequired_1 = require("./lib/paymentrequired");
var proxyerror_1 = require("./lib/proxyerror");
var serviceunvailable_1 = require("./lib/serviceunvailable");
var unauthorized_1 = require("./lib/unauthorized");
var paramsrequired_1 = require("./paramsrequired");
var mime_1 = require("./mime");
exports.HTTPException = exception_1.Exception;

@@ -31,47 +32,10 @@ exports.Exception = exception_1.Exception;

exports.Unauthorized = unauthorized_1.Unauthorized;
/**
*
* @param list
* @returns {function(Object, Object, Function): *}
*/
function paramsRequired() {
return paramsrequired_1.paramsRequired();
}
exports.paramsRequired = paramsRequired;
function mime(list) {
if (typeof list == 'string') {
list = [list];
}
return function (req, res, next) {
for (var i = 0; i < list.length; i++) {
if (!req.accepts(list[0])) {
throw new exports.NotAcceptable(list[0]);
}
}
next();
};
return mime_1.mime(list);
}
exports.mime = mime;
/**
*
* @returns {function(Express.Request, Express.Response, Function): *}
*/
function paramsRequired() {
return function (req, res, next) {
req.paramsRequired = function (fields) {
var a = [];
for (var field in fields) {
if (fields[field]) {
for (var i = 0; i < fields[field].length; i++) {
var key = fields[field][i];
if (this[field][key] === undefined) {
a.push(key);
}
}
}
}
if (a.length) {
throw new exports.BadRequest('Parameters required ' + a.join(', ') + '.');
}
};
next();
};
}
exports.paramsRequired = paramsRequired;
//# sourceMappingURL=index.js.map
import {Exception as _Exception} from "./lib/exception";
import {BadGateway as _BadGateway} from "./lib/types/badgateway";
import {BadRequest as _BadRequest} from "./lib/types/badrequest";
import {Forbidden as _Forbidden} from "./lib/types/forbidden";
import {GatewayTimeout as _GatewayTimeout} from "./lib/types/gatewaytimeout";
import {InternalServerError as _InternalServerError} from "./lib/types/internalservererror";
import {MethodNotAllowed as _MethodNotAllowed} from "./lib/types/methodnotallowed";
import {NotAcceptable as _NotAcceptable} from "./lib/types/notacceptable";
import {NotFound as _NotFound} from "./lib/types/notfound";
import {NotImplemented as _NotImplemented} from "./lib/types/notimplemented";
import {PaymentRequired as _PaymentRequired} from "./lib/types/paymentrequired";
import {ProxyError as _ProxyError} from "./lib/types/proxyerror";
import {ServiceUnvailable as _ServiceUnvailable} from "./lib/types/serviceunvailable";
import {Unauthorized as _Unauthorized} from "./lib/types/unauthorized";
import {BadGateway as _BadGateway} from "./lib/badgateway";
import {BadRequest as _BadRequest} from "./lib/badrequest";
import {Forbidden as _Forbidden} from "./lib/forbidden";
import {GatewayTimeout as _GatewayTimeout} from "./lib/gatewaytimeout";
import {InternalServerError as _InternalServerError} from "./lib/internalservererror";
import {MethodNotAllowed as _MethodNotAllowed} from "./lib/methodnotallowed";
import {NotAcceptable as _NotAcceptable} from "./lib/notacceptable";
import {NotFound as _NotFound} from "./lib/notfound";
import {NotImplemented as _NotImplemented} from "./lib/notimplemented";
import {PaymentRequired as _PaymentRequired} from "./lib/paymentrequired";
import {ProxyError as _ProxyError} from "./lib/proxyerror";
import {ServiceUnvailable as _ServiceUnvailable} from "./lib/serviceunvailable";
import {Unauthorized as _Unauthorized} from "./lib/unauthorized";
import {paramsRequired as _paramsRequired} from "./paramsrequired";
import {mime as _mime} from "./mime";
export interface ParamsRequired{
body?:Array<String>;
params?:Array<String>;
query?:Array<String>;
}

@@ -38,60 +35,8 @@ export const HTTPException = _Exception;

/**
*
* @param list
* @returns {function(Object, Object, Function): *}
*/
export function mime(list:Array<string>|string):Function{
if(typeof list == 'string'){
list = [<string>list];
}
return function(req:any, res:any, next:Function){
for(var i = 0; i < list.length; i++){
if (!req.accepts(list[0])){
throw new NotAcceptable(list[0]);
}
}
next();
}
export function paramsRequired(){
return _paramsRequired();
}
/**
*
* @returns {function(Express.Request, Express.Response, Function): *}
*/
export function paramsRequired(){
return function(req:any, res:any, next:Function){
req.paramsRequired = function(fields:ParamsRequired){
var a = [];
for(var field in fields){
if(fields[field]){
for(var i = 0; i < fields[field].length; i++){
var key = fields[field][i];
if(this[field][key] === undefined){
a.push(key);
}
}
}
}
if(a.length){
throw new BadRequest('Parameters required ' + a.join(', ') +'.');
}
};
next();
};
export function mime(list:Array<string>|string){
return _mime(list);
}

@@ -17,7 +17,4 @@ export declare class Error {

constructor(status:any, message?: string, innerException?: Error|string) {
constructor(status:any, message?: string, innerException?: any) {
// Guard against throw Exception(...) usage.
if (!(this instanceof Exception)) return new Exception(status, message, innerException);
Error.apply(this, arguments);

@@ -36,3 +33,3 @@

this.innerException = <Error> innerException;
this.message = this.message + ", innerException: " + this.innerException.message;
this.message = this.message + ", innerException: " + this.innerException.message ;
}

@@ -48,2 +45,4 @@ else if (typeof innerException === "string") {

}
this.message = (this.message+ " ").trim();
}

@@ -53,5 +52,5 @@

//console.warn(this.type + ': ' + this.status + ' ' + this.name + ' => ' + this.message)
return this.name + '('+this.status+'): ' + this.message;
return (this.name + '('+this.status+'): ' + this.message + " ").trim();
}
}
{
"name": "httpexceptions",
"version": "1.2.1",
"version": "1.2.2",
"description": "Provide exception for HTTP Rest API",
"main": "index.js",
"scripts": {
"build": "typings install && tsc",
"preinstall": "typings install",
"install": "tsc",
"pretest": "typings install && tsc",
"test": "mocha"
"postinstall": "tsc",
"test": "mocha --reporter spec --check-leaks --bail test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},

@@ -33,2 +33,3 @@ "repository": {

"chai": "^2.1.0",
"istanbul": "^0.4.2",
"mocha": "^2.4.5",

@@ -35,0 +36,0 @@ "typescript": "^1.7.5"

@@ -1,3 +0,6 @@

# HTTPExceptions [![Build Status](https://travis-ci.org/Romakita/httpexceptions.svg?branch=master)](https://travis-ci.org/Romakita/httpexceptions)
# HTTPExceptions
[![Build Status](https://travis-ci.org/Romakita/httpexceptions.svg?branch=master)](https://travis-ci.org/Romakita/httpexceptions)
[![Coverage Status](https://coveralls.io/repos/github/Romakita/httpexceptions/badge.svg?branch=master)](https://coveralls.io/github/Romakita/httpexceptions?branch=master)
> Provide Exceptions for REST API based on Express.js.

@@ -4,0 +7,0 @@

Sorry, the diff of this file is not supported yet