Skip to content

Commit

Permalink
segmentio#284 Added options for axiosRetryConfig, disable axiosRetry …
Browse files Browse the repository at this point in the history
…if retryCount is 0
  • Loading branch information
Dave committed Jun 30, 2021
1 parent aeda99e commit 452811b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions index.js
Expand Up @@ -27,6 +27,8 @@ class Analytics {
* @property {Boolean} [enable] (default: true)
* @property {Object} [axiosConfig] (optional)
* @property {Object} [axiosInstance] (default: axios.create(options.axiosConfig))
* @property {Object} [axiosRetryConfig] (optional)
* @property {Number} [retryCount] (default: 3)
*/

constructor (writeKey, options) {
Expand Down Expand Up @@ -54,11 +56,15 @@ class Analytics {
enumerable: true,
value: typeof options.enable === 'boolean' ? options.enable : true
})
axiosRetry(this.axiosInstance, {
retries: options.retryCount || 3,
retryCondition: this._isErrorRetryable,
retryDelay: axiosRetry.exponentialDelay
})
if (options.retryCount !== 0) {
axiosRetry(this.axiosInstance, {
retries: options.retryCount || 3,
retryDelay: axiosRetry.exponentialDelay,
...(options.axiosRetryConfig || {}),
// retryCondition is below optional config to ensure it does not get overridden
retryCondition: this._isErrorRetryable
})
}
}

_validate (message, type) {
Expand Down

0 comments on commit 452811b

Please sign in to comment.