Skip to content

Commit

Permalink
Switch from throwing to console.warn()ing on options in args
Browse files Browse the repository at this point in the history
  • Loading branch information
jlomas-stripe committed Sep 22, 2017
1 parent f1a65ef commit 4ec6955
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ var utils = module.exports = {
return OPTIONS_KEYS.indexOf(key) > -1;
});

if (argKeys.length > optionKeysInArgs.length) {
throw new Error(
if (optionKeysInArgs.length > 0) {
console.warn(
'Stripe: Options found in arguments (' + optionKeysInArgs.join(', ') + '). Did you mean to pass an options ' +
'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.'
);
Expand Down
15 changes: 14 additions & 1 deletion test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,20 @@ describe('utils', function() {
});
it('throws an error if the hash contains both data and options', function() {
var args = [{foo: 'bar', api_key: 'foo', idempotency_key: 'baz'}];
expect(function() { utils.getDataFromArgs(args); }).to.throw(/Options found in arguments/);

// Hack to make sure we're logging to console.warn here:
var _warn = console.warn;

console.warn = function(message) {
expect(message).to.equal(
'Stripe: Options found in arguments (api_key, idempotency_key).' +
' Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.'
);
};

utils.getDataFromArgs(args);

console.warn = _warn;
});
it('finds the data', function() {
var args = [{foo: 'bar'}, {api_key: 'foo'}];
Expand Down

0 comments on commit 4ec6955

Please sign in to comment.