How to use the @pollyjs/utils.EXPIRY_STRATEGIES.ERROR function in @pollyjs/utils

To help you get started, we’ve selected a few @pollyjs/utils 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 Netflix / pollyjs / packages / @pollyjs / adapter / src / index.js View on Github external
const recordingEntry = await this.persister.findEntry(pollyRequest);

    if (recordingEntry) {
      await pollyRequest._emit('beforeReplay', recordingEntry);

      if (isExpired(recordingEntry.startedDateTime, config.expiresIn)) {
        const message =
          'Recording for the following request has expired.\n' +
          `${stringifyRequest(pollyRequest, null, 2)}`;

        switch (config.expiryStrategy) {
          // exit into the record flow if expiryStrategy is "record".
          case EXPIRY_STRATEGIES.RECORD:
            return this.record(pollyRequest);
          // throw an error and exit if expiryStrategy is "error".
          case EXPIRY_STRATEGIES.ERROR:
            this.assert(message);
            break;
          // log a warning and continue if expiryStrategy is "warn".
          case EXPIRY_STRATEGIES.WARN:
            console.warn(`[Polly] ${message}`);
            break;
          // throw an error if we encounter an unsupported expiryStrategy.
          default:
            this.assert(
              `Invalid config option passed for "expiryStrategy": "${config.expiryStrategy}"`
            );
            break;
        }
      }

      await this.timeout(pollyRequest, recordingEntry);
github DefinitelyTyped / DefinitelyTyped / types / pollyjs__core / pollyjs__core-tests.ts View on Github external
import { Polly, Timing, setupMocha, setupQunit } from '@pollyjs/core';
import { EXPIRY_STRATEGIES, MODES } from '@pollyjs/utils';

const polly = new Polly('test recording', {
    mode: MODES.PASSTHROUGH,
    recordFailedRequests: true,
    adapters: ['xhr', 'fetch'],
    persister: 'rest',
    expiryStrategy: EXPIRY_STRATEGIES.ERROR,
    timing: Timing.relative(3),
    matchRequestsBy: {
        method: true,
        headers: true,
        body: true,
        order: true,

        url: {
            protocol: true,
            username: true,
            password: true,
            hostname: true,
            port: true,
            pathname: true,
            query: true,
            hash: false,