diff --git a/index.js b/index.js index c8c9df4..15024e0 100644 --- a/index.js +++ b/index.js @@ -6,15 +6,13 @@ var mischief = require('./mischief'); // prototype defined here. var chaos_monkeyware = module.exports = function (options) { - // Set default values for those not provided by user. - options = options || {}; - options.probability = options.probability || 0.1; + var probability = options.probability || 0.1; return function middleware (req, res, next) { var mischiefNames, mischiefName; // First, decide whether to do anything at all. - if (Math.random() > 1 - options.probability) { + if (Math.random() > 1 - probability) { // Select a mischief at random. mischiefNames = Object.keys(mischief); @@ -24,7 +22,7 @@ var chaos_monkeyware = module.exports = function (options) { // that this failure was... special. res.setHeader('ChaosMonkeyWare', mischiefName); - if (options.logger) { + if (options && typeof options.logger === 'function') { options.logger('ChaosMonkeyWare mischief: ' + mischiefName); }