From 1cdb80f143fb9d0393cfe4c5298457982579dd95 Mon Sep 17 00:00:00 2001 From: Leah Jones Date: Tue, 1 Mar 2016 08:05:17 -0800 Subject: [PATCH] Always set a default empty `{}` value for client `opts` Fixes #154 --- lib/clients/client.js | 13 +++++++------ lib/clients/web/client.js | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/clients/client.js b/lib/clients/client.js index 0bd0115c3..f80f89355 100644 --- a/lib/clients/client.js +++ b/lib/clients/client.js @@ -32,6 +32,7 @@ var callTransport = require('./transports/call-transport'); * @constructor */ function BaseAPIClient(token, opts) { + var clientOpts = opts || {}; EventEmitter.call(this); /** @@ -41,18 +42,18 @@ function BaseAPIClient(token, opts) { this._token = token; /** @type {string} */ - this.slackAPIUrl = opts.slackAPIUrl || 'https://slack.com/api/'; + this.slackAPIUrl = clientOpts.slackAPIUrl || 'https://slack.com/api/'; /** @type {Function} */ - this.transport = opts.transport || requestsTransport; + this.transport = clientOpts.transport || requestsTransport; /** @type {string} */ - this.userAgent = opts.userAgent || 'node-slack'; + this.userAgent = clientOpts.userAgent || 'node-slack'; /** * Default to attempting 5 retries within 5 minutes, with exponential backoff. */ - this.retryConfig = opts.retryConfig || { + this.retryConfig = clientOpts.retryConfig || { retries: 5, factor: 3.9 }; @@ -64,14 +65,14 @@ function BaseAPIClient(token, opts) { */ this.requestQueue = async.priorityQueue( bind(this._callTransport, this), - opts.maxRequestConcurrency || 3 + clientOpts.maxRequestConcurrency || 3 ); /** * The logger function attached to this client. * @type {Function} */ - this.logger = opts.logger || getLogger(opts.logLevel); + this.logger = clientOpts.logger || getLogger(clientOpts.logLevel); this._createFacets(); } diff --git a/lib/clients/web/client.js b/lib/clients/web/client.js index bd5c91ec7..0680c23cd 100644 --- a/lib/clients/web/client.js +++ b/lib/clients/web/client.js @@ -20,7 +20,8 @@ var facets = require('./facets/index'); * @constructor */ function WebAPIClient(token, opts) { - BaseAPIClient.call(this, token, opts); + var clientOpts = opts || {}; + BaseAPIClient.call(this, token, clientOpts); } inherits(WebAPIClient, BaseAPIClient);