-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import axiosFactory from "axios"; | ||
|
||
const retryDelay = 1000; | ||
|
||
export const http = axiosFactory.create({ | ||
headers: { | ||
"x-agent": "automod", | ||
}, | ||
}); | ||
|
||
http.interceptors.response.use(undefined, function axiosRetryInterceptor(err) { | ||
const config = err.config; | ||
|
||
console.error({ | ||
status: err.response?.status, | ||
data: JSON.stringify(err.response?.data), | ||
}); | ||
|
||
if ( | ||
err.response?.status && | ||
(err.response.status === 429 || err.response.status >= 500) && | ||
!config.__retryCount | ||
) { | ||
config.__retryCount = 0; | ||
} | ||
|
||
if (config.__retryCount < 3) { | ||
// Max retry limit | ||
config.__retryCount += 1; | ||
const backoffDelay = 2 ** config.__retryCount * retryDelay; | ||
console.warn(`Received HTTP ${err.response.status}, retrying in ${backoffDelay}ms`); | ||
|
||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(http(config)); | ||
}, backoffDelay); | ||
}); | ||
} | ||
|
||
return Promise.reject(err); | ||
}); |
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,2 @@ | ||
User-agent: * | ||
Disallow: |