-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow for customizing retry strategy (box/box-codegen#635) (#457)
Co-authored-by: box-sdk-build <[email protected]>
- Loading branch information
1 parent
09765a4
commit 530ca33
Showing
6 changed files
with
266 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{ "engineHash": "cc6ffb8", "specHash": "6886603", "version": "1.9.0" } | ||
{ "engineHash": "a2387ff", "specHash": "6886603", "version": "1.9.0" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Configuration | ||
|
||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
|
||
- [Max retry attempts](#max-retry-attempts) | ||
- [Custom retry strategy](#custom-retry-strategy) | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
||
## Max retry attempts | ||
|
||
The default maximum number of retries in case of failed API call is 5. | ||
To change this number you should initialize `BoxRetryStrategy` with the new value and pass it to `NetworkSession`. | ||
|
||
```js | ||
const auth = new BoxDeveloperTokenAuth({ token: 'DEVELOPER_TOKEN_GOES_HERE' }); | ||
const networkSession = new NetworkSession({ | ||
retryStrategy: new BoxRetryStrategy({ maxAttempts: 6 }), | ||
}); | ||
const client = new BoxClient({ auth, networkSession }); | ||
``` | ||
|
||
## Custom retry strategy | ||
|
||
You can also implement your own retry strategy by subclassing `RetryStrategy` and overriding `shouldRetry` and `retryAfter` methods. | ||
This example shows how to set custom strategy that retries on 5xx status codes and waits 1 second between retries. | ||
|
||
```ts | ||
export class CustomRetryStrategy implements RetryStrategy { | ||
async shouldRetry( | ||
fetchOptions: FetchOptions, | ||
fetchResponse: FetchResponse, | ||
attemptNumber: number, | ||
): Promise<boolean> { | ||
return false; | ||
} | ||
|
||
retryAfter( | ||
fetchOptions: FetchOptions, | ||
fetchResponse: FetchResponse, | ||
attemptNumber: number, | ||
): number { | ||
return 1.0; | ||
} | ||
} | ||
|
||
const auth = new BoxDeveloperTokenAuth({ token: 'DEVELOPER_TOKEN_GOES_HERE' }); | ||
const networkSession = new NetworkSession({ | ||
retryStrategy: new CustomRetryStrategy(), | ||
}); | ||
const client = new BoxClient({ auth, networkSession }); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.