Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

#284 Added options for axiosRetryConfig, disable axiosRetry if retryCount is 0 #285

Merged
merged 3 commits into from
Jul 28, 2021
Merged
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
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here it should be === 0, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No? If the user sets a retryCount specifically of 0 then we do not need axiosRetry :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Sorry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries :D Its always good to double check :)
Appreciate the review!

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