epo-ops-sdk
Version:
TypeScript SDK for the European Patent Office's Open Patent Services (OPS) API with OAuth support
26 lines • 996 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.withRetry = withRetry;
const errors_1 = require("../errors");
async function withRetry(operation, options = {}) {
const { maxRetries = 3, initialDelay = 1000, maxDelay = 10000, backoffFactor = 2, shouldRetry = (error) => error instanceof errors_1.RateLimitError } = options;
let lastError;
let delay = initialDelay;
for (let attempt = 0; attempt <= maxRetries; attempt++) {
try {
return await operation();
}
catch (error) {
lastError = error;
if (attempt === maxRetries || !shouldRetry(lastError)) {
throw lastError;
}
// Wait before retrying
await new Promise(resolve => setTimeout(resolve, delay));
// Increase delay for next attempt
delay = Math.min(delay * backoffFactor, maxDelay);
}
}
throw lastError;
}
//# sourceMappingURL=retry.js.map