Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* Linear retry. Retry time delay grows linearly.
*/
FIXED
}
// Default values of RetryOptions
const DEFAULT_RETRY_OPTIONS: StorageRetryOptions = {
maxRetryDelayInMs: 120 * 1000,
maxTries: 4,
retryDelayInMs: 4 * 1000,
retryPolicyType: StorageRetryPolicyType.EXPONENTIAL,
tryTimeoutInMs: undefined // Use server side default timeout strategy
};
const RETRY_ABORT_ERROR = new AbortError("The operation was aborted.");
/**
* Retry policy with exponential retry and linear retry implemented.
*
* @class RetryPolicy
* @extends {BaseRequestPolicy}
*/
export class StorageRetryPolicy extends BaseRequestPolicy {
/**
* RetryOptions.
*
* @private
* @type {RetryOptions}
* @memberof StorageRetryPolicy
*/
private readonly retryOptions: StorageRetryOptions;
* Linear retry. Retry time delay grows linearly.
*/
FIXED
}
// Default values of StorageRetryOptions
const DEFAULT_RETRY_OPTIONS: StorageRetryOptions = {
maxRetryDelayInMs: 120 * 1000,
maxTries: 4,
retryDelayInMs: 4 * 1000,
retryPolicyType: StorageRetryPolicyType.EXPONENTIAL,
secondaryHost: "",
tryTimeoutInMs: 30 * 1000 // https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations
};
const RETRY_ABORT_ERROR = new AbortError("The operation was aborted.");
/**
* Retry policy with exponential retry and linear retry implemented.
*
* @class RetryPolicy
* @extends {BaseRequestPolicy}
*/
export class StorageRetryPolicy extends BaseRequestPolicy {
/**
* RetryOptions.
*
* @private
* @type {RetryOptions}
* @memberof StorageRetryPolicy
*/
private readonly retryOptions: StorageRetryOptions;
receive(onMessage: OnMessage, onError: OnError, abortSignal?: AbortSignalLike): ReceiveHandler {
this._throwIfReceiverOrConnectionClosed();
this._throwIfAlreadyReceiving();
const baseConsumer = this._baseConsumer!;
if (typeof onMessage !== "function") {
throw new TypeError("The parameter 'onMessage' must be of type 'function'.");
}
if (typeof onError !== "function") {
throw new TypeError("The parameter 'onError' must be of type 'function'.");
}
// return immediately if the abortSignal is already aborted.
if (abortSignal && abortSignal.aborted) {
onError(new AbortError("The receive operation has been cancelled by the user."));
// close this receiver when user triggers a cancellation.
this.close().catch(() => {}); // no-op close error handler
return new ReceiveHandler(baseConsumer);
}
const wrappedOnError = (error: Error) => {
// ignore retryable errors
if ((error as MessagingError).retryable) {
return;
}
logger.warning(
"[%s] Since the error is not retryable, we let the user know about it by calling the user's error handler.",
this._context.connectionId
);
logErrorStackTrace(error);
async abort(): Promise {
const desc: string =
`[${this._context.connectionId}] The receive operation on the Receiver "${this.name}" with ` +
`address "${this.address}" has been cancelled by the user.`;
// Cancellation is user-intended, so log to info instead of warning.
logger.info(desc);
if (this._onError) {
const error = new AbortError("The receive operation has been cancelled by the user.");
this._onError(error);
}
this.clearHandlers();
await this.close();
}
/**
* Linear retry. Retry time delay grows linearly.
*/
FIXED
}
// Default values of RetryOptions
const DEFAULT_RETRY_OPTIONS: RetryOptions = {
maxRetryDelayInMs: 120 * 1000,
maxTries: 4,
retryDelayInMs: 4 * 1000,
retryPolicyType: RetryPolicyType.EXPONENTIAL,
tryTimeoutInMs: undefined // Use server side default timeout strategy
};
const RETRY_ABORT_ERROR = new AbortError("The operation was aborted.");
/**
* Retry policy with exponential retry and linear retry implemented.
*
* @class RetryPolicy
* @extends {BaseRequestPolicy}
*/
export class RetryPolicy extends BaseRequestPolicy {
/**
* RetryOptions.
*
* @private
* @type {RetryOptions}
* @memberof RetryPolicy
*/
private readonly retryOptions: RetryOptions;
const rejectOnAbort = () => {
const requestName = options.requestName;
const desc: string =
`[${this._context.connectionId}] The request "${requestName}" ` +
`to has been cancelled by the user.`;
// Cancellation is user-intended behavior, so log to info instead of warning.
logger.info(desc);
const error = new AbortError(
`The ${requestName ? requestName + " " : ""}operation has been cancelled by the user.`
);
reject(error);
};
const rejectOnAbort = () => {
const desc: string = `[${this._context.connectionId}] The create batch operation has been cancelled by the user.`;
// Cancellation is user-intented, so treat as info instead of warning.
logger.info(desc);
const error = new AbortError(`The create batch operation has been cancelled by the user.`);
reject(error);
};
public sendRequest(request: WebResource): Promise {
const xhr = new XMLHttpRequest();
if (request.proxySettings) {
throw new Error("HTTP proxy is not supported in browser environment");
}
const abortSignal = request.abortSignal;
if (abortSignal) {
if (abortSignal.aborted) {
return Promise.reject(new AbortError("The operation was aborted."));
}
const listener = () => {
xhr.abort();
};
abortSignal.addEventListener("abort", listener);
xhr.addEventListener("readystatechange", () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
abortSignal.removeEventListener("abort", listener);
}
});
}
addProgressListener(xhr.upload, request.onUploadProgress);
addProgressListener(xhr, request.onDownloadProgress);
const rejectOnAbort = async (): Promise => {
logOnAbort();
try {
await this.close();
} finally {
return reject(new AbortError("The receive operation has been cancelled by the user."));
}
};