From d9118ff21cbbe5b0c6db49c6cc0796ab1f8faf78 Mon Sep 17 00:00:00 2001 From: Markko Paas Date: Fri, 18 Jul 2014 15:55:16 +0200 Subject: [PATCH] Remove writing to options object. This allows options parameter to be readonly --- index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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); }