@@ -155,6 +155,29 @@ const requestOptionProperties = [
155155 'sessionIdContext' ,
156156] as const
157157
158+ export interface RetryOptions {
159+ /**
160+ * If this set to true, it will take precedence over all other retry options.
161+ * @default false
162+ */
163+ disableRetry ?: boolean
164+ /**
165+ * The maximum amount of retries for a request.
166+ * @default 1
167+ */
168+ maximumRetryCount ?: number
169+ /**
170+ * The minimum duration (in milliseconds) for the exponential backoff algorithm.
171+ * @default 100
172+ */
173+ baseDelayMs ?: number
174+ /**
175+ * The maximum duration (in milliseconds) for the exponential backoff algorithm.
176+ * @default 60000
177+ */
178+ maximumDelayMs ?: number
179+ }
180+
158181export interface ClientOptions {
159182 endPoint : string
160183 accessKey ?: string
@@ -169,6 +192,7 @@ export interface ClientOptions {
169192 credentialsProvider ?: CredentialProvider
170193 s3AccelerateEndpoint ?: string
171194 transportAgent ?: http . Agent
195+ retryOptions ?: RetryOptions
172196}
173197
174198export type RequestOption = Partial < IRequest > & {
@@ -212,6 +236,7 @@ export class TypedClient {
212236 protected credentialsProvider ?: CredentialProvider
213237 partSize : number = 64 * 1024 * 1024
214238 protected overRidePartSize ?: boolean
239+ protected retryOptions : RetryOptions
215240
216241 protected maximumPartSize = 5 * 1024 * 1024 * 1024
217242 protected maxObjectSize = 5 * 1024 * 1024 * 1024 * 1024
@@ -352,6 +377,20 @@ export class TypedClient {
352377 this . s3AccelerateEndpoint = params . s3AccelerateEndpoint || undefined
353378 this . reqOptions = { }
354379 this . clientExtensions = new Extensions ( this )
380+
381+ if ( params . retryOptions ) {
382+ if ( ! isObject ( params . retryOptions ) ) {
383+ throw new errors . InvalidArgumentError (
384+ `Invalid retryOptions type: ${ params . retryOptions } , expected to be type "object"` ,
385+ )
386+ }
387+
388+ this . retryOptions = params . retryOptions
389+ } else {
390+ this . retryOptions = {
391+ disableRetry : false ,
392+ }
393+ }
355394 }
356395 /**
357396 * Minio extensions that aren't necessary present for Amazon S3 compatible storage servers
@@ -724,7 +763,14 @@ export class TypedClient {
724763 reqOptions . headers . authorization = signV4 ( reqOptions , this . accessKey , this . secretKey , region , date , sha256sum )
725764 }
726765
727- const response = await requestWithRetry ( this . transport , reqOptions , body )
766+ const response = await requestWithRetry (
767+ this . transport ,
768+ reqOptions ,
769+ body ,
770+ this . retryOptions . disableRetry === true ? 0 : this . retryOptions . maximumRetryCount ,
771+ this . retryOptions . baseDelayMs ,
772+ this . retryOptions . maximumDelayMs ,
773+ )
728774 if ( ! response . statusCode ) {
729775 throw new Error ( "BUG: response doesn't have a statusCode" )
730776 }
0 commit comments