-
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.
Add DevRev httpClient. Gracefully handle failed attachments. (#19)
- Add exponential retry and handle rate-limiting towards DevRev. - Gracefully handle failure to upload extracted attachments. https://app.devrev.ai/devrev/works/ISS-143265
- Loading branch information
Showing
9 changed files
with
103 additions
and
39 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import axios, { AxiosError } from 'axios'; | ||
import axiosRetry from 'axios-retry'; | ||
|
||
const axiosDevRevClient = axios.create(); | ||
|
||
axiosRetry(axiosDevRevClient, { | ||
retries: 5, | ||
retryDelay: (retryCount, error) => { | ||
console.warn( | ||
'Retry attempt: ' + retryCount + 'to url: ' + error.config?.url + '.' | ||
); | ||
if (error.response) { | ||
const retry_after = error.response?.headers['retry-after']; | ||
if (retry_after) { | ||
return retry_after; | ||
} | ||
} | ||
// Exponential backoff algorithm: 1 * 2 ^ retryCount * 1000ms | ||
return axiosRetry.exponentialDelay(retryCount, error, 1000); | ||
}, | ||
retryCondition: (error: AxiosError) => { | ||
return ( | ||
axiosRetry.isNetworkOrIdempotentRequestError(error) || | ||
error.response?.status === 429 | ||
); | ||
}, | ||
onMaxRetryTimesExceeded(error: AxiosError, retryCount) { | ||
console.log(`Max retries attempted: ${retryCount}`); | ||
delete error.config?.headers.Authorization; | ||
delete error.request._header; | ||
}, | ||
}); | ||
|
||
export { axios, axiosDevRevClient }; |
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