httpexceptions
Advanced tools
Comparing version 1.0.11 to 1.1.0
30
index.js
/// <reference path="type.d.ts" /> | ||
var HTTPException; | ||
(function (HTTPException_1) { | ||
var debugEnable = true; | ||
HTTPException_1.HTTPException = require('./lib/http-exception'); | ||
@@ -19,6 +18,2 @@ HTTPException_1.BadGateway = require('./lib/types/badgateway'); | ||
HTTPException_1.Unauthorized = require('./lib/types/unauthorized'); | ||
function debug(b) { | ||
debugEnable = b; | ||
} | ||
HTTPException_1.debug = debug; | ||
/** | ||
@@ -62,3 +57,3 @@ * | ||
if (a.length) { | ||
throw new HTTPException_1.BadRequest(a); | ||
throw new HTTPException_1.BadRequest('Parameters required ' + a.join(', ') + '.'); | ||
} | ||
@@ -70,27 +65,4 @@ }; | ||
HTTPException_1.paramsRequired = paramsRequired; | ||
/** | ||
* | ||
* @returns {function(any, Express.Request, Express.Response): undefined} | ||
*/ | ||
function globalHandler() { | ||
return function (err, req, res) { | ||
if (err instanceof HTTPException_1.HTTPException) { | ||
try { | ||
res.status(err.status) | ||
.send(err.getMessage()); | ||
} | ||
catch (er) { | ||
console.log('unable to run getMessage() method'); | ||
res.status(err.status) | ||
.send(err.message); | ||
} | ||
if (debugEnable) { | ||
throw err; | ||
} | ||
} | ||
}; | ||
} | ||
HTTPException_1.globalHandler = globalHandler; | ||
})(HTTPException || (HTTPException = {})); | ||
module.exports = HTTPException; | ||
//# sourceMappingURL=index.js.map |
33
index.ts
@@ -11,4 +11,2 @@ /// <reference path="type.d.ts" /> | ||
var debugEnable = true; | ||
export var HTTPException = require('./lib/http-exception'); | ||
@@ -29,5 +27,2 @@ export var BadGateway = require('./lib/types/badgateway'); | ||
export function debug(b:boolean){ | ||
debugEnable = b; | ||
} | ||
/** | ||
@@ -83,3 +78,3 @@ * | ||
if(a.length){ | ||
throw new BadRequest(a); | ||
throw new BadRequest('Parameters required ' + a.join(', ') +'.'); | ||
} | ||
@@ -92,28 +87,2 @@ }; | ||
/** | ||
* | ||
* @returns {function(any, Express.Request, Express.Response): undefined} | ||
*/ | ||
export function globalHandler(){ | ||
return function(err:any, req:Express.Request, res:Express.Response){ | ||
if (err instanceof HTTPException) { | ||
try{ | ||
res.status(err.status) | ||
.send(err.getMessage()); | ||
}catch(er){ | ||
console.log('unable to run getMessage() method'); | ||
res.status(err.status) | ||
.send(err.message); | ||
} | ||
if(debugEnable){ | ||
throw err; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
@@ -120,0 +89,0 @@ |
{ | ||
"name": "httpexceptions", | ||
"version": "1.0.11", | ||
"version": "1.1.0", | ||
"description": "Provide exception for HTTP Rest API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
171478
3726