Refactor for better API
This commit is contained in:
parent
c391aede1f
commit
c3781a432e
1 changed files with 3 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import * as fetchRetryFactory from "fetch-retry";
|
||||
import { RequestInitRetryParams } from "fetch-retry";
|
||||
import { Logger } from "src/tracing/logger";
|
||||
|
||||
const fetchWithRetry = fetchRetryFactory.default(fetch);
|
||||
|
|
@ -15,10 +16,9 @@ function getUrlFromInput(input: RequestInfo | URL): string {
|
|||
|
||||
export async function retriedFetch(
|
||||
input: RequestInfo | URL,
|
||||
init: RequestInit = {}
|
||||
init: RequestInitRetryParams<typeof fetch> = {}
|
||||
): Promise<Response> {
|
||||
return fetchWithRetry(input, {
|
||||
...init,
|
||||
retryOn: function (attempt, error, response) {
|
||||
if (error !== null || !response || response.status >= 500) {
|
||||
Logger.getInstance().warn(
|
||||
|
|
@ -33,5 +33,6 @@ export async function retriedFetch(
|
|||
},
|
||||
retries: 6,
|
||||
retryDelay: (attempt) => Math.pow(1.5, attempt) * 500,
|
||||
...init,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue