jkhsjdhjs / node-fetch-cookies

node-fetch wrapper that adds support for cookie-jars
MIT License
28 stars 16 forks source link

Request #2

Closed Null-crypto closed 4 years ago

Null-crypto commented 4 years ago

I'm finding this lib extremely helpful but the console.warn for ignored cookies is very inconvenient. Could I kindly ask that it is removed or made optional.

addCookie(cookie, fromURL) {
    if(typeof cookie === "string") {
        try {
            cookie = new Cookie(cookie, fromURL);
        }
        catch(error) {
            if(error instanceof CookieParseError) {
                console.warn("Ignored cookie: " + cookie);
                console.warn("Reason: " + error.message);
                return false;
            }
            throw error;
        }
    }
jkhsjdhjs commented 4 years ago

I made it optional. You can now pass a callback function to the CookieJar constructor which is called when a cookie has been ignored: https://github.com/jkhsjdhjs/node-fetch-cookies#new-cookiejarfile-flags--rw-cookies-cookieignorecallback