Sha256: c2a8822c74e2e96c20b79a7c2c4427230daf7ed4d367ef387763bca7e2fccd34

Contents?: true

Size: 1.94 KB

Versions: 26

Compression:

Stored size: 1.94 KB

Contents

import { toPublicUrl } from './toPublicUrl.mjs';
import { InternalError, devUtils } from '../internal/devUtils.mjs';
async function onUnhandledRequest(request, strategy = "warn") {
  const url = new URL(request.url);
  const publicUrl = toPublicUrl(url) + url.search;
  const requestBody = request.method === "HEAD" || request.method === "GET" ? null : await request.clone().text();
  const messageDetails = `

  \u2022 ${request.method} ${publicUrl}

${requestBody ? `  \u2022 Request body: ${requestBody}

` : ""}`;
  const unhandledRequestMessage = `intercepted a request without a matching request handler:${messageDetails}If you still wish to intercept this unhandled request, please create a request handler for it.
Read more: https://mswjs.io/docs/getting-started/mocks`;
  function applyStrategy(strategy2) {
    switch (strategy2) {
      case "error": {
        devUtils.error("Error: %s", unhandledRequestMessage);
        throw new InternalError(
          devUtils.formatMessage(
            'Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'
          )
        );
      }
      case "warn": {
        devUtils.warn("Warning: %s", unhandledRequestMessage);
        break;
      }
      case "bypass":
        break;
      default:
        throw new InternalError(
          devUtils.formatMessage(
            'Failed to react to an unhandled request: unknown strategy "%s". Please provide one of the supported strategies ("bypass", "warn", "error") or a custom callback function as the value of the "onUnhandledRequest" option.',
            strategy2
          )
        );
    }
  }
  if (typeof strategy === "function") {
    strategy(request, {
      warning: applyStrategy.bind(null, "warn"),
      error: applyStrategy.bind(null, "error")
    });
    return;
  }
  if (url.protocol === "file:") {
    return;
  }
  applyStrategy(strategy);
}
export {
  onUnhandledRequest
};
//# sourceMappingURL=onUnhandledRequest.mjs.map

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.25 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.24 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.23 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.22 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.21 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.20 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.19 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.18 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.17 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.16 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.15 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.14 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.13 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.12 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.11 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.10 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.9 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.8 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs
clapton-0.0.7 lib/clapton/javascripts/node_modules/msw/lib/core/utils/request/onUnhandledRequest.mjs