How to use the @azure/abort-controller.AbortError function in @azure/abort-controller

To help you get started, we’ve selected a few @azure/abort-controller examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-sdk-for-js / sdk / storage / storage-file-share / src / policies / StorageRetryPolicy.ts View on Github external
/**
   * 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;
github Azure / azure-sdk-for-js / sdk / storage / storage-queue / src / policies / StorageRetryPolicy.ts View on Github external
* 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;
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / src / receiver.ts View on Github external
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);
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / src / eventHubReceiver.ts View on Github external
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();
  }
github Azure / azure-sdk-for-js / sdk / storage / storage-file / src / policies / RetryPolicy.ts View on Github external
/**
   * 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;
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / src / managementClient.ts View on Github external
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);
          };
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / src / eventHubSender.ts View on Github external
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);
      };
github Azure / azure-sdk-for-js / sdk / core / core-http / lib / xhrHttpClient.ts View on Github external
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);
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / src / receiver.ts View on Github external
const rejectOnAbort = async (): Promise => {
          logOnAbort();
          try {
            await this.close();
          } finally {
            return reject(new AbortError("The receive operation has been cancelled by the user."));
          }
        };

@azure/abort-controller

Microsoft Azure SDK for JavaScript - Aborter

MIT
Latest version published 9 months ago

Package Health Score

81 / 100
Full package analysis