File tree Expand file tree Collapse file tree 5 files changed +41
-8
lines changed Expand file tree Collapse file tree 5 files changed +41
-8
lines changed Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 11import axios , { type Axios } from 'axios'
2+ import axiosRetry , { exponentialDelay } from 'axios-retry'
23
34import { 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}
Original file line number Diff line number Diff line change 11import type { Axios , AxiosRequestConfig } from 'axios'
2+ import type { AxiosRetry } from 'axios-retry'
23
34export type SeamHttpOptions =
45 | SeamHttpOptionsFromEnv
@@ -9,9 +10,12 @@ export type SeamHttpOptions =
910interface SeamHttpCommonOptions {
1011 endpoint ?: string
1112 axiosOptions ?: AxiosRequestConfig
13+ axiosRetryOptions ?: AxiosRetryConfig
1214 enableLegacyMethodBehaivor ?: boolean
1315}
1416
17+ type AxiosRetryConfig = Parameters < AxiosRetry > [ 1 ]
18+
1519export type SeamHttpOptionsFromEnv = SeamHttpCommonOptions
1620
1721export interface SeamHttpOptionsWithClient
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments