From 63fe16443e25eb798ec9f8feff4888feb8d50f61 Mon Sep 17 00:00:00 2001 From: sliterok Date: Fri, 29 May 2020 19:26:47 +0500 Subject: [PATCH] Moved definition of CookieJar.cookies because it caused TypeError on constructor Creating new CookieJar instance while passing array of Cookies as third argument causes typeError `new CookieJar('', 'r', cookies)` ```(node:29588) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'get' of undefined at CookieJar.addCookie (\node_modules\node-fetch-cookies\src\cookie-jar.mjs:44:26) at \node_modules\node-fetch-cookies\src\cookie-jar.mjs:15:44 at CoreMongooseArray.forEach () at new CookieJar (\node_modules\node-fetch-cookies\src\cookie-jar.mjs:15:21)``` --- src/cookie-jar.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cookie-jar.mjs b/src/cookie-jar.mjs index 761e3d8..e05e158 100644 --- a/src/cookie-jar.mjs +++ b/src/cookie-jar.mjs @@ -5,6 +5,8 @@ import {paramError, CookieParseError} from "./errors.mjs"; export default class CookieJar { constructor(file, flags = "rw", cookies, cookieIgnoreCallback) { + this.cookies = new Map(); + if(file && typeof file !== "string") throw paramError("Second", "file", "new CookieJar()", "string"); if(typeof flags !== "string") @@ -22,7 +24,6 @@ export default class CookieJar { throw paramError("Fourth", "cookieIgnoreCallback", "new CookieJar()", "function"); this.file = file; this.flags = flags; - this.cookies = new Map(); this.cookieIgnoreCallback = cookieIgnoreCallback; } addCookie(cookie, fromURL) {