middlewarify
Advanced tools
Comparing version 0.3.6 to 0.3.7
@@ -31,15 +31,4 @@ /** | ||
var middObj = Object.create(null); | ||
middObj.mainCallback = noopMidd; | ||
middObj.mainCallback.isMain = true; | ||
var middObj = middlewarify.newMidd(); | ||
/** | ||
* The default parameters object. | ||
* | ||
* @type {Object} | ||
*/ | ||
var defaultParams = { | ||
beforeAfter: false, | ||
}; | ||
if (__.isFunction(optFinalCb)) { | ||
@@ -57,2 +46,12 @@ middObj.mainCallback = optFinalCb; | ||
} | ||
/** | ||
* The default parameters object. | ||
* | ||
* @type {Object} | ||
*/ | ||
var defaultParams = { | ||
beforeAfter: false, | ||
catchAll: null, | ||
}; | ||
middObj.params = __.extend(defaultParams, params); | ||
@@ -74,2 +73,15 @@ | ||
/** | ||
* Create an initialize a new Middleware Object. | ||
* | ||
* @return {Object} A new Middleware Object. | ||
*/ | ||
middlewarify.newMidd = function() { | ||
var middObj = Object.create(null); | ||
middObj.mainCallback = noopMidd; | ||
middObj.mainCallback.isMain = true; | ||
return middObj; | ||
}; | ||
/** | ||
* Invokes all the middleware. | ||
@@ -102,2 +114,9 @@ * @param {Object} middObj Internal midd object. | ||
middlewarify._fetchAndInvoke(midds, args, store, deferred); | ||
}).catch(function(err) { | ||
// check for catchAll error handler. | ||
if (typeof middObj.params.catchAll === 'function') { | ||
middObj.params.catchAll(err); | ||
} else { | ||
throw err; | ||
} | ||
}); | ||
@@ -104,0 +123,0 @@ }; |
{ | ||
"name": "middlewarify", | ||
"description": "Apply the middleware pattern to any function.", | ||
"version": "0.3.6", | ||
"version": "0.3.7", | ||
"homepage": "https://github.com/thanpolas/middlewarify", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -162,2 +162,3 @@ # Middlewarify | ||
* `beforeAfter` type: **Boolean**, default: `false` If set to true the Before/After hooks will be used instead of the single queue `use` hook, which is the default, view the [example displayed above](#using-the-before--after-middleware-type). | ||
* `catchAll` type **Function**, default: `null` If defined all errors will be piped to this callback, useful when Middleware is used as Express middleware. | ||
@@ -275,2 +276,5 @@ #### The use(fn) Method | ||
## Release History | ||
- **v0.3.7**, *03 Mar 2014* | ||
- Added `catchAll` option for cases where invocations have no error handlers. | ||
- **v0.3.6**, *02 Mar 2014* | ||
@@ -277,0 +281,0 @@ - Optimizations and better handling of errors. |
@@ -259,2 +259,16 @@ /** | ||
test('5.1.4 Catch All option', function(done) { | ||
var custObj = Object.create(null); | ||
midd.make(custObj, 'create', function() { | ||
throw new Error('an error'); | ||
}, { | ||
catchAll: function(err) { | ||
assert.instanceOf(err, Error, '"err" should be instanceOf Error'); | ||
assert.equal(err.message, 'an error', 'Error message should match'); | ||
done(); | ||
}, | ||
}); | ||
custObj.create(); | ||
}); | ||
}); | ||
@@ -261,0 +275,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
43569
914
314