From 6f5ddf16518e071b26f23fcc98647df421ca365b Mon Sep 17 00:00:00 2001 From: James Waters Date: Fri, 11 Aug 2023 23:24:48 +0100 Subject: [PATCH] Wrap getCookiesSync in try/catch --- src/utils/proxy/cookie-jar.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/utils/proxy/cookie-jar.js b/src/utils/proxy/cookie-jar.js index 708fc919..b4e07e19 100644 --- a/src/utils/proxy/cookie-jar.js +++ b/src/utils/proxy/cookie-jar.js @@ -39,17 +39,20 @@ export function addCookieToJar(url, headers) { } export function importCookieHeader(url, cookieHeader) { - const cookies = cookieHeader.split(';') + const cookies = cookieHeader.split(';'); for (let i = 0; i < cookies.length; i += 1) { - const [key, value] = cookies[i].trim().split('=') + const [key, value] = cookies[i].trim().split('='); // If there's an existing cookie with a matching key for this url, - // we want to update it - const existingCookie = cookieJar.getCookiesSync(url).find(existing => existing.key === key) + // we want to update it. Otherwise, we add a new cookie + let existingCookie; + try { + existingCookie = cookieJar.getCookiesSync(url).find(existing => existing.key === key); + } catch {} + if (existingCookie) { existingCookie.value = value; } else { - // Otherwise we add a new cookie cookieJar.setCookieSync(new Cookie({ key, value }), url.toString(), { ignoreError: true });