@microsoft/kiota-http-fetchlibrary
Version:
Kiota request adapter implementation with fetch
54 lines • 2.21 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 RedirectHandlerOptionKey = "RedirectHandlerOption";
/**
* MiddlewareOptions
* A class representing RedirectHandlerOptions
*/
export class RedirectHandlerOptions {
/**
*
* To create an instance of RedirectHandlerOptions
* @param [options] - The redirect handler options instance
* @returns An instance of RedirectHandlerOptions
* @throws Error if maxRedirects is more than 20 or less than 0
* @example const options = new RedirectHandlerOptions({ maxRedirects: 5 });
*/
constructor(options = {}) {
var _a, _b;
if (options.maxRedirects && options.maxRedirects > RedirectHandlerOptions.MAX_MAX_REDIRECTS) {
const error = new Error(`MaxRedirects should not be more than ${RedirectHandlerOptions.MAX_MAX_REDIRECTS}`);
error.name = "MaxLimitExceeded";
throw error;
}
if (options.maxRedirects !== undefined && options.maxRedirects < 0) {
const error = new Error(`MaxRedirects should not be negative`);
error.name = "MinExpectationNotMet";
throw error;
}
this.maxRedirects = (_a = options.maxRedirects) !== null && _a !== void 0 ? _a : RedirectHandlerOptions.DEFAULT_MAX_REDIRECTS;
this.shouldRedirect = (_b = options.shouldRedirect) !== null && _b !== void 0 ? _b : RedirectHandlerOptions.defaultShouldRetry;
}
getKey() {
return RedirectHandlerOptionKey;
}
}
/**
* A member holding default max redirects value
*/
RedirectHandlerOptions.DEFAULT_MAX_REDIRECTS = 5;
/**
* A member holding maximum max redirects value
*/
RedirectHandlerOptions.MAX_MAX_REDIRECTS = 20;
/**
*
* A member holding default shouldRedirect callback
* @returns true
*/
RedirectHandlerOptions.defaultShouldRetry = () => true;
//# sourceMappingURL=redirectHandlerOptions.js.map