@microsoft/kiota-http-fetchlibrary
Version:
Kiota request adapter implementation with fetch
84 lines • 3.22 kB
JavaScript
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
export const RetryHandlerOptionKey = "RetryHandlerOptionKey";
/**
* RequestOption
* Options
* Class for RetryHandlerOptions
*/
export class RetryHandlerOptions {
/**
*
* To create an instance of RetryHandlerOptions
* @param options - The RetryHandlerOptionsParams object
* @returns An instance of RetryHandlerOptions
* @example const options = new RetryHandlerOptions({ maxRetries: 4 });
*/
constructor(options = {}) {
var _a, _b, _c;
if (options.delay !== undefined && options.delay > RetryHandlerOptions.MAX_DELAY) {
throw this.createError(`Delay should not be more than ${RetryHandlerOptions.MAX_DELAY}`, "MaxLimitExceeded");
}
if (options.maxRetries !== undefined && options.maxRetries > RetryHandlerOptions.MAX_MAX_RETRIES) {
throw this.createError(`MaxRetries should not be more than ${RetryHandlerOptions.MAX_MAX_RETRIES}`, "MaxLimitExceeded");
}
if (options.delay !== undefined && options.delay < 0) {
throw this.createError(`Delay should not be negative`, "MinExpectationNotMet");
}
if (options.maxRetries !== undefined && options.maxRetries < 0) {
throw this.createError(`MaxRetries should not be negative`, "MinExpectationNotMet");
}
this.delay = Math.min((_a = options.delay) !== null && _a !== void 0 ? _a : RetryHandlerOptions.DEFAULT_DELAY, RetryHandlerOptions.MAX_DELAY);
this.maxRetries = Math.min((_b = options.maxRetries) !== null && _b !== void 0 ? _b : RetryHandlerOptions.DEFAULT_MAX_RETRIES, RetryHandlerOptions.MAX_MAX_RETRIES);
this.shouldRetry = (_c = options.shouldRetry) !== null && _c !== void 0 ? _c : RetryHandlerOptions.defaultShouldRetry;
}
/**
*
* Creates an error object with a message and name
* @param message - The error message
* @param name - The error name
* @returns An error object
*/
createError(message, name) {
const error = new Error(message);
error.name = name;
return error;
}
/**
*
* To get the maximum delay
* @returns A maximum delay
*/
getMaxDelay() {
return RetryHandlerOptions.MAX_DELAY;
}
getKey() {
return RetryHandlerOptionKey;
}
}
/**
* A member holding default delay value in seconds
*/
RetryHandlerOptions.DEFAULT_DELAY = 3;
/**
* A member holding default maxRetries value
*/
RetryHandlerOptions.DEFAULT_MAX_RETRIES = 3;
/**
* A member holding maximum delay value in seconds
*/
RetryHandlerOptions.MAX_DELAY = 180;
/**
* A member holding maximum maxRetries value
*/
RetryHandlerOptions.MAX_MAX_RETRIES = 10;
/**
* A member holding default shouldRetry callback
* @returns true
*/
RetryHandlerOptions.defaultShouldRetry = () => true;
//# sourceMappingURL=retryHandlerOptions.js.map