dat-middleware
Advanced tools
Comparing version 1.5.9 to 1.5.10
@@ -80,2 +80,5 @@ var error = require('./error'); | ||
}; | ||
RequestData.prototype.execErr = function (err, req, res, next) { | ||
this.exec(req, res, next, err); | ||
}; | ||
/** | ||
@@ -86,2 +89,3 @@ * @method | ||
var self = this; | ||
var mwErr = arguments[3]; // hack, cant accept 4 args else middleware will be considered errorHandler | ||
var errors = []; | ||
@@ -107,3 +111,3 @@ if (this.nextOnFirstError) { | ||
else if (step.type.indexOf('transform') === 0) { | ||
self._transformStep(req, step); | ||
self._transformStep(step, req, mwErr); | ||
} | ||
@@ -122,3 +126,3 @@ else { | ||
else if (step.type.indexOf('transform') === 0) { | ||
self._transformStep(req, step); | ||
self._transformStep(step, req, mwErr); | ||
} | ||
@@ -342,3 +346,3 @@ else { | ||
RequestData.prototype.set = function (key, value) { | ||
return this.transform(function (data, req) { | ||
return this.transform(function (data, req, err) { | ||
data = utils.set(key, value)(data); | ||
@@ -369,2 +373,17 @@ if (typeof key === 'object') { | ||
/** | ||
* set key to err | ||
* @param {key} string - key to set value for or key-value set object | ||
* @param {value} string - value to set for key | ||
* or | ||
* @param {obj} string - key to set value for or key-value set object | ||
*/ | ||
RequestData.prototype.setToErr = function (key) { | ||
this.transform(function (data, req, err) { | ||
data[key] = err; | ||
return data; | ||
}); | ||
return this.execErr.bind(this); | ||
}; | ||
/*************** CONDITIONALS ***************/ | ||
@@ -447,3 +466,3 @@ /*************** CONDITIONALS ***************/ | ||
}; | ||
RequestData.prototype._transformStep = function (req, step) { | ||
RequestData.prototype._transformStep = function (step, req, err) { | ||
if (step.type === 'transform') { | ||
@@ -455,3 +474,3 @@ var keypath = this.keypath.bind(this); | ||
.map(reqValueForKeypath) | ||
.map(bindRight(step.transformation, req)) | ||
.map(bindRight(step.transformation, req, err)) | ||
.forEach(setValueForKey); | ||
@@ -461,3 +480,3 @@ } | ||
var dataType = this.dataType; | ||
req[dataType] = step.transformation(req[dataType], req); | ||
req[dataType] = step.transformation(req[dataType], req, err); | ||
} | ||
@@ -464,0 +483,0 @@ else { |
{ | ||
"name": "dat-middleware", | ||
"version": "1.5.9", | ||
"version": "1.5.10", | ||
"description": "common request, response, body, query, and param validation, transformation, and flow control middleware", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
var express = require('express'); | ||
var mw = require('../../index'); | ||
var next = function (req, res, next) {next();} | ||
var next = function (req, res, next) {next();}; | ||
@@ -5,0 +5,0 @@ module.exports = function createAppWithMiddleware (middleware, middleware2, middleware3) { |
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
66550
31
1829