-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Exported `axios` and `axiosClient` with exponential backoff retry mechanism for HTTP requests. - Resolved issues with circular structure logging. - Fixed attachments metadata normalization bug. - Improved repository logging.
- Loading branch information
1 parent
baf79e1
commit dcf33de
Showing
18 changed files
with
183 additions
and
57 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 |
---|---|---|
|
@@ -130,4 +130,4 @@ dist | |
.pnp.* | ||
|
||
.npmrc | ||
.idea | ||
.idea |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import axios, { AxiosError } from 'axios'; | ||
import axiosRetry from 'axios-retry'; | ||
|
||
const axiosClient = axios.create(); | ||
|
||
// Exponential backoff algorithm: Retry 3 times and there will be a delay of more than 1 * no. of retries second + random number of milliseconds between each retry. | ||
axiosRetry(axiosClient, { | ||
retries: 3, | ||
retryDelay: (retryCount, error) => { | ||
console.log(`Retry attempt: ${retryCount} of ${error.config?.url}.`); | ||
return axiosRetry.exponentialDelay(retryCount, error, 1000); | ||
}, | ||
retryCondition: (error: AxiosError) => { | ||
if ( | ||
error.response?.status && | ||
error.response?.status >= 500 && | ||
error.response?.status <= 599 | ||
) { | ||
return true; | ||
} else if (error.response?.status === 429) { | ||
console.log( | ||
'Rate limit exceeded. Delay: ' + error.response.headers['retry-after'] | ||
); | ||
return false; | ||
} else { | ||
return false; | ||
} | ||
}, | ||
onMaxRetryTimesExceeded(error: AxiosError, retryCount) { | ||
console.log(`Max retries attempted: ${retryCount}`); | ||
delete error.config?.headers.Authorization; | ||
delete error.request._header; | ||
}, | ||
}); | ||
|
||
export { axios, axiosClient }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './client'; | ||
export * from './types'; | ||
export * from './axios-client'; |
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,3 +1,7 @@ | ||
/** | ||
* HTTP Response type | ||
* @deprecated | ||
*/ | ||
export type HTTPResponse = { | ||
success: boolean; | ||
message: string; | ||
|
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.