Closed TimDaub closed 1 year ago
I think this is not an error in cross-fetch.
When you make a get request to the test4.com website, which is likely to be a real website it will be sending an HTML document instead of a JSON payload, hence the first character of the returned html page is <
This makes the response an invalid JSON response, and that's is triggering this error. I suggest you to fetch content from a website/API endpoint that returns a JSON payload instead of HTML and see if that resolves this error.
@TimDaub thanks for taking the time to open this issue. I assume that error is being thrown when running on Node since node-fetch is the lib that implements FetchError. Note that whatwg-fetch does not seem to implement it, so it's unlikely the instanceof
comparison you've mentioned to work in browser environments.
E.g. if I wanted to compare with
instanceof
where would I find the "FetchError" that cross-fetch throws when it comes across a non-parsable JSON body and throws uponawait result.json()
.I've not found anything on Google and MDN related to FetchError so I'm wondering where it stems from. Hopefully not my own code lol.