Skip to content

Commit 358caba

Browse files
committed
Add axios-retry
1 parent 8015b9b commit 358caba

File tree

5 files changed

+41
-8
lines changed

5 files changed

+41
-8
lines changed

package-lock.json

Lines changed: 23 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
}
8585
},
8686
"dependencies": {
87-
"axios": "^1.5.0"
87+
"axios": "^1.5.0",
88+
"axios-retry": "^3.8.0"
8889
},
8990
"devDependencies": {
9091
"@seamapi/fake-seam-connect": "^1.18.0",

src/lib/seam/connect/axios.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import axios, { type Axios } from 'axios'
2+
import axiosRetry, { exponentialDelay } from 'axios-retry'
23

34
import { paramsSerializer } from 'lib/params-serializer.js'
45

@@ -13,16 +14,23 @@ export const createAxiosClient = (
1314
options: Required<SeamHttpOptions>,
1415
): Axios => {
1516
if (isSeamHttpOptionsWithClient(options)) return options.client
16-
// TODO: axiosRetry? Allow options to configure this if so
17-
return axios.create({
17+
18+
const client = axios.create({
1819
baseURL: options.endpoint,
1920
withCredentials: isSeamHttpOptionsWithClientSessionToken(options),
2021
paramsSerializer,
2122
...options.axiosOptions,
2223
headers: {
2324
...getAuthHeaders(options),
2425
...options.axiosOptions.headers,
25-
// TODO: User-Agent
2626
},
2727
})
28+
29+
axiosRetry(client, {
30+
retries: 2,
31+
retryDelay: exponentialDelay,
32+
...options.axiosRetryOptions,
33+
})
34+
35+
return client
2836
}

src/lib/seam/connect/client-options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Axios, AxiosRequestConfig } from 'axios'
2+
import type { AxiosRetry } from 'axios-retry'
23

34
export type SeamHttpOptions =
45
| SeamHttpOptionsFromEnv
@@ -9,9 +10,12 @@ export type SeamHttpOptions =
910
interface SeamHttpCommonOptions {
1011
endpoint?: string
1112
axiosOptions?: AxiosRequestConfig
13+
axiosRetryOptions?: AxiosRetryConfig
1214
enableLegacyMethodBehaivor?: boolean
1315
}
1416

17+
type AxiosRetryConfig = Parameters<AxiosRetry>[1]
18+
1519
export type SeamHttpOptionsFromEnv = SeamHttpCommonOptions
1620

1721
export interface SeamHttpOptionsWithClient

src/lib/seam/connect/parse-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const parseOptions = (
3434
...(apiKey != null ? { apiKey } : {}),
3535
endpoint,
3636
axiosOptions: options.axiosOptions ?? {},
37+
axiosRetryOptions: options.axiosRetryOptions ?? {},
3738
enableLegacyMethodBehaivor:
3839
options.enableLegacyMethodBehaivor ?? enableLegacyMethodBehaivorDefault,
3940
}

0 commit comments

Comments
 (0)