diff --git a/src/index.ts b/src/index.ts index e5ae1833..e2a71273 100755 --- a/src/index.ts +++ b/src/index.ts @@ -67,6 +67,7 @@ type Version = ObjectValues class Storyblok { private client: SbFetch private maxRetries: number + private retriesDelay: number private throttle: ThrottleFn private accessToken: string private cache: ISbCache @@ -137,7 +138,8 @@ class Storyblok { this.setComponentResolver(config.componentResolver) } - this.maxRetries = config.maxRetries || 5 + this.maxRetries = config.maxRetries || 10 + this.retriesDelay = 300 this.throttle = throttledQueue(this.throttledRequest, rateLimit, 1000) this.accessToken = config.accessToken || '' this.relations = {} as RelationsType @@ -585,10 +587,6 @@ class Storyblok { params: ISbStoriesParams, retries?: number ): Promise { - if (typeof retries === 'undefined' || !retries) { - retries = 0 - } - const cacheKey = this.helpers.stringify({ url: url, params: params }) const provider = this.cacheProvider() @@ -643,11 +641,11 @@ class Storyblok { return resolve(response) } catch (error: Error | any) { if (error.response && error.status === 429) { - retries = retries ? retries + 1 : 0 + retries = typeof retries === 'undefined' ? 0 : retries + 1 if (retries < this.maxRetries) { - console.log(`Hit rate limit. Retrying in ${retries} seconds.`) - await this.helpers.delay(1000 * retries) + console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1000} seconds.`) + await this.helpers.delay(this.retriesDelay) return this.cacheResponse(url, params, retries) .then(resolve) .catch(reject)