Skip to content

Use autorest's integrated retry policy instead of the locally implemented #1829

@davidyuk

Description

@davidyuk

replace

export const genRetryOnFailurePolicy = (
retryCount: number,
retryOverallDelay: number,
): AdditionalPolicyConfig => ({
policy: {
name: 'retry-on-failure',
async sendRequest(request, next) {
const statusesToNotRetry = [200, 400, 403];
const intervals = new Array(retryCount).fill(0)
.map((_, idx) => ((idx + 1) / retryCount) ** 2);
const intervalSum = intervals.reduce((a, b) => a + b);
const intervalsInMs = intervals.map((el) => (el / intervalSum) * retryOverallDelay);
let error = new RestError('Not expected to be thrown');
for (let attempt = 0; attempt <= retryCount; attempt += 1) {
if (attempt !== 0) await pause(intervalsInMs[attempt - 1]);
try {
return await next(request);
} catch (e) {
if (!(e instanceof RestError)) throw e;
if (statusesToNotRetry.includes(e.response?.status ?? 0)) throw e;
error = e;
}
}
throw error;
},
},
position: 'perCall',
});

with
https://learn.microsoft.com/en-us/javascript/api/@azure/core-rest-pipeline/?view=azure-node-latest#@azure-core-rest-pipeline-exponentialretrypolicy

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions