forked from cvat-ai/cvat
-
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.
cvat-core: retry HTTP requests if a 429 status is returned (cvat-ai#7216
- Loading branch information
Showing
6 changed files
with
61 additions
and
19 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,4 @@ | ||
### Added | ||
|
||
- The UI will now retry requests that were rejected due to rate limiting | ||
(<https://github.com/opencv/cvat/pull/7216>) |
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,25 @@ | ||
// Copyright (C) 2023 CVAT.ai Corporation | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
import Axios from 'axios'; | ||
import axiosRetry from 'axios-retry'; | ||
|
||
Axios.defaults.withCredentials = true; | ||
Axios.defaults.xsrfHeaderName = 'X-CSRFTOKEN'; | ||
Axios.defaults.xsrfCookieName = 'csrftoken'; | ||
|
||
axiosRetry(Axios, { | ||
retryCondition: (error) => error.response && error.response.status === Axios.HttpStatusCode.TooManyRequests, | ||
retryDelay: (retryCount, error) => { | ||
const retryAfterValue = error.response.headers['retry-after']; | ||
|
||
// Retry-After is allowed to be a decimal integer as well as a date. | ||
// We're probably not going to use the latter option, though, so don't bother parsing it. | ||
if (!retryAfterValue || !/^\d+$/.test(retryAfterValue)) { | ||
return axiosRetry.exponentialDelay(retryCount, error); | ||
} | ||
|
||
return parseInt(retryAfterValue, 10) * 1000; | ||
}, | ||
}); |
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