Wrap getCookiesSync in try/catch
This commit is contained in:
parent
7a9a266560
commit
6f5ddf1651
@ -39,17 +39,20 @@ export function addCookieToJar(url, headers) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function importCookieHeader(url, cookieHeader) {
|
export function importCookieHeader(url, cookieHeader) {
|
||||||
const cookies = cookieHeader.split(';')
|
const cookies = cookieHeader.split(';');
|
||||||
for (let i = 0; i < cookies.length; i += 1) {
|
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,
|
// If there's an existing cookie with a matching key for this url,
|
||||||
// we want to update it
|
// we want to update it. Otherwise, we add a new cookie
|
||||||
const existingCookie = cookieJar.getCookiesSync(url).find(existing => existing.key === key)
|
let existingCookie;
|
||||||
|
try {
|
||||||
|
existingCookie = cookieJar.getCookiesSync(url).find(existing => existing.key === key);
|
||||||
|
} catch {}
|
||||||
|
|
||||||
if (existingCookie) {
|
if (existingCookie) {
|
||||||
existingCookie.value = value;
|
existingCookie.value = value;
|
||||||
} else {
|
} else {
|
||||||
// Otherwise we add a new cookie
|
|
||||||
cookieJar.setCookieSync(new Cookie({
|
cookieJar.setCookieSync(new Cookie({
|
||||||
key, value
|
key, value
|
||||||
}), url.toString(), { ignoreError: true });
|
}), url.toString(), { ignoreError: true });
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user