sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API
MIT License
11.91k stars 342 forks source link

Always get error TypeError: Failed to fetch #513

Closed naivefun closed 9 months ago

naivefun commented 1 year ago

I'd expect the error could be several kinds of type, but the catched exception is always TypeError: Failed to fetch. Is there options wrong?

I need access error code like ERR_NETWORK ERR_TOO_MANY_REDIRECTS etc ....

test.js

import ky from "ky";

ky("https://www.githubbbbbb.com")
  .text()
  .catch((e) => {
    console.log(e.name, e.message);
  });

run node test.js and it prints out TypeError fetch failed

image

sholladay commented 11 months ago

Fetch often throws very vague errors, unfortunately.

Try in a different browser. I find that Firefox and Safari in particular is usually the most informative.

sindresorhus commented 9 months ago

We cannot do anything about the errors Fetch throws.

Share your opinions here: https://github.com/whatwg/fetch/issues/526