feat(WEB-300): add retry for fetch calls
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import merge from "deepmerge"
|
||||
import fetchRetry from "fetch-retry"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
@@ -18,6 +19,13 @@ const defaultOptions: RequestInit = {
|
||||
mode: "cors",
|
||||
}
|
||||
|
||||
const fetch = fetchRetry(global.fetch, {
|
||||
retries: 3,
|
||||
retryDelay: function (attempt, error, response) {
|
||||
return Math.pow(2, attempt) * 150 // 150, 300, 600
|
||||
},
|
||||
})
|
||||
|
||||
export async function get(
|
||||
endpoint: Endpoint,
|
||||
options: RequestOptionsWithOutBody,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import fetchRetry from "fetch-retry"
|
||||
import { DocumentNode } from "graphql"
|
||||
import { GraphQLClient } from "graphql-request"
|
||||
import { cache } from "react"
|
||||
@@ -13,6 +14,12 @@ const client = new GraphQLClient(env.CMS_URL, {
|
||||
url: URL | RequestInfo,
|
||||
params: RequestInit | undefined
|
||||
) {
|
||||
const fetch = fetchRetry(global.fetch, {
|
||||
retries: 3,
|
||||
retryDelay: function (attempt, error, response) {
|
||||
return Math.pow(2, attempt) * 150 // 150, 300, 600
|
||||
},
|
||||
})
|
||||
return fetch(url, params)
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user