express-contracts
Advanced tools
Comparing version 2.2.0 to 3.0.0
{ | ||
"name": "express-contracts", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "Express.js plugin for checking request and response with rho-contracts", | ||
@@ -5,0 +5,0 @@ "license": "BSD-2-Clause", |
@@ -18,5 +18,9 @@ var c = require('rho-contracts-fork'); | ||
return function (req, res, next) { | ||
// Error handler may want to use checkedJson even in case of ValidationError, so extend first. | ||
extendWithCheckedJson(res, responseBodyContract, next); | ||
validateRequest(req, requestContract, next); | ||
// Validation functions throw synchronous errors, which will be caught | ||
// by Express and propagated to downstream middleware. | ||
// Error handler may want to use checkedJson even in case of | ||
// ValidationError, so extend first. | ||
extendWithCheckedJson(res, responseBodyContract); | ||
validateRequest(req, requestContract); | ||
next(); | ||
@@ -30,9 +34,5 @@ }; | ||
var extendWithCheckedJson = function (res, responseBodyContract, next) { | ||
var extendWithCheckedJson = function (res, responseBodyContract) { | ||
res.checkedJson = function (payload) { | ||
try { | ||
responseBodyContract.check(payload); | ||
} catch (e) { | ||
return next(e); | ||
} | ||
responseBodyContract.check(payload); | ||
res.json(payload); | ||
@@ -42,3 +42,3 @@ }; | ||
var validateRequest = function (req, requestContract, next) { | ||
var validateRequest = function (req, requestContract) { | ||
// Check each field (body, query, params) individually so that we don't | ||
@@ -62,3 +62,3 @@ // dump the *entire* express req object into the error message. | ||
var prefix = 'Validation error in ' + relevantKeyDescriptions[key] + ':\n'; | ||
return next(new errors.ValidationError(prefix + e.message, key)); | ||
throw new errors.ValidationError(prefix + e.message, key); | ||
} | ||
@@ -65,0 +65,0 @@ }; |
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
14946
219