Innovenergy_trunk/frontend/node_modules/testcafe/lib/proxyless/request-pipeline/safe-api.js

62 lines
9.1 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.safeFailRequest = exports.safeContinueRequest = exports.safeFulfillRequest = exports.safeContinueResponse = void 0;
const debug_loggers_1 = require("../../utils/debug-loggers");
const cdp_1 = require("../utils/cdp");
const INVALID_INTERCEPTED_RESPONSE_ERROR_MSG = 'Invalid InterceptionId.';
// In some cases (a request was aborted, any page that initiated the request doesn't exist, etc.)
// Chrome Debug Protocol doesn't allow to continue request pipeline
// and raises the "Invalid InterceptionId" error.
// We use the simplest way to fix it - omit such an error.
async function connectionResetGuard(handleRequestFn, handleErrorFn) {
try {
await handleRequestFn();
}
catch (err) {
if (err.message === INVALID_INTERCEPTED_RESPONSE_ERROR_MSG)
return;
handleErrorFn(err);
throw err;
}
}
async function safeContinueResponse(client, data) {
const isPausedEvent = (0, cdp_1.isRequestPausedEvent)(data);
await connectionResetGuard(async () => {
const param = isPausedEvent
? { requestId: data.requestId }
: data;
await client.Fetch.continueResponse(param);
}, err => {
const formatter = isPausedEvent ? '%r' : '%s';
(0, debug_loggers_1.requestPipelineLogger)(`Fetch.continueResponse. Unhandled error %s during processing ${formatter}`, err, data);
});
}
exports.safeContinueResponse = safeContinueResponse;
async function safeFulfillRequest(client, fulfillInfo) {
await connectionResetGuard(async () => {
await client.Fetch.fulfillRequest(fulfillInfo);
}, err => {
(0, debug_loggers_1.requestPipelineLogger)(`Fetch.fulfillRequest. Unhandled error %s during processing %s`, err, fulfillInfo.requestId);
});
}
exports.safeFulfillRequest = safeFulfillRequest;
async function safeContinueRequest(client, event) {
await connectionResetGuard(async () => {
await client.Fetch.continueRequest({ requestId: event.requestId });
}, err => {
(0, debug_loggers_1.requestPipelineLogger)(`Fetch.continueRequest. Unhandled error %s during processing %r`, err, event);
});
}
exports.safeContinueRequest = safeContinueRequest;
async function safeFailRequest(client, event, errorReason = 'Aborted') {
await connectionResetGuard(async () => {
await client.Fetch.failRequest({
requestId: event.requestId,
errorReason,
});
}, err => {
(0, debug_loggers_1.requestPipelineLogger)(`Fetch.failRequest. Unhandled error %s during processing %s`, err, event.requestId);
});
}
exports.safeFailRequest = safeFailRequest;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2FmZS1hcGkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcHJveHlsZXNzL3JlcXVlc3QtcGlwZWxpbmUvc2FmZS1hcGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQ0EsNkRBQWtFO0FBTWxFLHNDQUFvRDtBQUVwRCxNQUFNLHNDQUFzQyxHQUFHLHlCQUF5QixDQUFDO0FBRXpFLGlHQUFpRztBQUNqRyxtRUFBbUU7QUFDbkUsaURBQWlEO0FBQ2pELDBEQUEwRDtBQUUxRCxLQUFLLFVBQVUsb0JBQW9CLENBQUUsZUFBb0MsRUFBRSxhQUFpQztJQUN4RyxJQUFJO1FBQ0EsTUFBTSxlQUFlLEVBQUUsQ0FBQztLQUMzQjtJQUNELE9BQU8sR0FBUSxFQUFFO1FBQ2IsSUFBSSxHQUFHLENBQUMsT0FBTyxLQUFLLHNDQUFzQztZQUN0RCxPQUFPO1FBRVgsYUFBYSxDQUFDLEdBQUcsQ0FBQyxDQUFDO1FBRW5CLE1BQU0sR0FBRyxDQUFDO0tBQ2I7QUFDTCxDQUFDO0FBRU0sS0FBSyxVQUFVLG9CQUFvQixDQUFFLE1BQW1CLEVBQUUsSUFBa0Q7SUFDL0csTUFBTSxhQUFhLEdBQUcsSUFBQSwwQkFBb0IsRUFBQyxJQUFJLENBQUMsQ0FBQztJQUVqRCxNQUFNLG9CQUFvQixDQUFDLEtBQUssSUFBSSxFQUFFO1FBQ2xDLE1BQU0sS0FBSyxHQUFHLGFBQWE7WUFDdkIsQ0FBQyxDQUFDLEVBQUUsU0F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