Last active
August 29, 2015 13:57
-
-
Save reggi/9621592 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require("underscore"); | |
var helper = {}; | |
var middleware = {}; | |
helper.reclusive = function(callback) { | |
var items = []; | |
items.push(function(req, res, next) { | |
return callback(null, req, res, next); | |
}); | |
items.push(function(err, req, res, next) { | |
return callback(err, req, res, next); | |
}); | |
return items; | |
} | |
middleware.random = function(req, res, next){ | |
var random = !! Math.round(Math.random() * 1); | |
var err = (random) ? new Error("there's an error") : null; | |
return next(err); | |
} | |
middleware.log = function(err, req, res, next){ | |
// send something to database regardless of error | |
console.log("database"); | |
return next(err); | |
} | |
middleware.send = function(err, req, res, next){ | |
if(err) return res.send("yeah "+ err.message) | |
return res.send("no error"); | |
} | |
module.exports = _.flatten([ | |
middleware.random, | |
helper.reclusive(middleware.log), | |
helper.reclusive(middleware.send), | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment