index: export CookieParseError
readme: add short description of CookieParseError error: add semicolons
This commit is contained in:
parent
200d3b0a7c
commit
2271c2e055
@ -47,6 +47,7 @@ import {fetch, CookieJar} from "node-fetch-cookies";
|
||||
})();
|
||||
```
|
||||
|
||||
|
||||
## Documentation
|
||||
|
||||
### async fetch(cookieJar, url[, options])
|
||||
@ -78,8 +79,8 @@ Alternatively this can also be a string, for example a serialized cookie receive
|
||||
In this case `fromURL` must be specified.
|
||||
- `fromURL` The url a cookie has been received from.
|
||||
|
||||
Returns `true` if the cookie has been added successfully. Returns `false` otherwise.
|
||||
Will log a warning to console if a cookie fails to be parsed.
|
||||
Returns `true` if the cookie has been added successfully. Returns `false` otherwise.
|
||||
If the parser throws a [CookieParseError](#class-cookieparseerror) it will be caught and a warning will be printed to console.
|
||||
|
||||
#### domains()
|
||||
Returns an iterator over all domains currently stored cookies for.
|
||||
@ -141,6 +142,9 @@ Returns whether the cookie has expired or not.
|
||||
#### isValidForRequest(url)
|
||||
Returns whether the cookie is valid for a request to `url`.
|
||||
|
||||
### Class: CookieParseError
|
||||
The Error that is thrown when the cookie parser located in the constructor of the [Cookie](#class-cookie) class is unable to parse the input.
|
||||
|
||||
|
||||
## 1.3.0 Breaking API Changes
|
||||
- `new CookieJar(flags, file, cookies)` has been changed to `new CookieJar(file, flags = "rw", cookies)`.
|
||||
|
@ -3,10 +3,10 @@ export class CookieParseError extends Error {
|
||||
super(...args);
|
||||
this.name = "CookieParseError";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export function paramError(position, paramName, functionName, validTypes) {
|
||||
validTypes = [validTypes].flatMap(t => "\"" + t + "\"");
|
||||
validTypes = validTypes.slice(0, -1).join(", ") + (validTypes.length > 1 ? " or " : "") + validTypes.slice(-1);
|
||||
return new TypeError(`${position} parameter "${paramName}" passed to "${functionName}" is not of type ${validTypes}!`);
|
||||
}
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
import _fetch from "node-fetch";
|
||||
import CookieJar from "./cookie-jar.mjs";
|
||||
import Cookie from "./cookie.mjs";
|
||||
import { paramError } from "./errors.mjs"
|
||||
import { paramError, CookieParseError } from "./errors.mjs"
|
||||
|
||||
async function fetch(cookieJars, url, options) {
|
||||
let cookies = "";
|
||||
@ -46,4 +46,4 @@ async function fetch(cookieJars, url, options) {
|
||||
return result;
|
||||
}
|
||||
|
||||
export {fetch, CookieJar, Cookie};
|
||||
export {fetch, CookieJar, Cookie, CookieParseError};
|
||||
|
Loading…
x
Reference in New Issue
Block a user