Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Allow option parameter to be readonly object #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down