Function parameter defaults?

The function below (defined in pre-request at the collection level) requires the postman data from the current request that is calling it. Is there anyway I can make it so I do not have to include postman myself when I call the function? Make it global or is there a way to specify it uses postman by default if not provided. Eg so supplying the value in the function call becomes optional.

Object.prototype.fail = (msg, postman) => {
    pm.test(pm.info.requestName, () => { throw new Error(msg) });
    console.info(pm.info.requestName + " | " + msg);
    postman.setNextRequest(null);
};

pm.fail("This has failed for a reason",postman);

Hmm on reading further you can specify a default value. I wonder if this will work…

Object.prototype.fail = (msg, postman=postman) => {
    pm.test(pm.info.requestName, () => { throw new Error(msg) });
    console.info(pm.info.requestName + " | " + msg);
    postman.setNextRequest(null);
};

pm.fail("This has failed for a reason");

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.