1- import globalAxios from "axios" ;
1+ import globalAxios , { AxiosError } from "axios" ;
2+ import axiosRetry from "axios-retry" ;
23import * as fs from "fs" ;
34import {
45 User as UserModel ,
@@ -77,6 +78,7 @@ export class Coinbase {
7778 * @param options.useServerSigner - Whether to use a Server-Signer or not.
7879 * @param options.debugging - If true, logs API requests and responses to the console.
7980 * @param options.basePath - The base path for the API.
81+ * @param options.maxNetworkRetries - The maximum number of network retries for the API GET requests.
8082 * @throws {InternalError } If the configuration is invalid.
8183 * @throws {InvalidAPIKeyFormat } If not able to create JWT token.
8284 */
@@ -86,6 +88,7 @@ export class Coinbase {
8688 useServerSigner = false ,
8789 debugging = false ,
8890 basePath = BASE_PATH ,
91+ maxNetworkRetries = 3 ,
8992 } : CoinbaseOptions ) {
9093 if ( apiKeyName === "" ) {
9194 throw new InternalError ( "Invalid configuration: apiKeyName is empty" ) ;
@@ -98,6 +101,15 @@ export class Coinbase {
98101 basePath : basePath ,
99102 } ) ;
100103 const axiosInstance = globalAxios . create ( ) ;
104+ axiosRetry ( axiosInstance , {
105+ retries : maxNetworkRetries ,
106+ retryCondition : ( error : AxiosError ) => {
107+ return (
108+ error . config ?. method ?. toUpperCase ( ) === "GET" &&
109+ ( error . response ?. status || 0 ) in [ 500 , 502 , 503 , 504 ]
110+ ) ;
111+ } ,
112+ } ) ;
101113 registerAxiosInterceptors (
102114 axiosInstance ,
103115 config => coinbaseAuthenticator . authenticateRequest ( config , debugging ) ,
0 commit comments