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

express-contracts

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

express-contracts - npm Package Compare versions

Comparing version 2.2.0 to 3.0.0

2

package.json
{
"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 @@ };

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