62 lines
9.1 KiB
JavaScript
62 lines
9.1 KiB
JavaScript
"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2FmZS1hcGkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcHJveHlsZXNzL3JlcXVlc3QtcGlwZWxpbmUvc2FmZS1hcGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQ0EsNkRBQWtFO0FBTWxFLHNDQUFvRDtBQUVwRCxNQUFNLHNDQUFzQyxHQUFHLHlCQUF5QixDQUFDO0FBRXpFLGlHQUFpRztBQUNqRyxtRUFBbUU7QUFDbkUsaURBQWlEO0FBQ2pELDBEQUEwRDtBQUUxRCxLQUFLLFVBQVUsb0JBQW9CLENBQUUsZUFBb0MsRUFBRSxhQUFpQztJQUN4RyxJQUFJO1FBQ0EsTUFBTSxlQUFlLEVBQUUsQ0FBQztLQUMzQjtJQUNELE9BQU8sR0FBUSxFQUFFO1FBQ2IsSUFBSSxHQUFHLENBQUMsT0FBTyxLQUFLLHNDQUFzQztZQUN0RCxPQUFPO1FBRVgsYUFBYSxDQUFDLEdBQUcsQ0FBQyxDQUFDO1FBRW5CLE1BQU0sR0FBRyxDQUFDO0tBQ2I7QUFDTCxDQUFDO0FBRU0sS0FBSyxVQUFVLG9CQUFvQixDQUFFLE1BQW1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