Replies: 0 comments 1 reply
-
I also face similar issue, when working with https://github.com/octokit/request-error.js they seems to pass fetch underlining error to the cause, so we get something like
I was looking for a way to type the fetch error, so I can check for which syscall failed, and guess that the problem is related to network issue. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
using Node.js 18.17.1
After switching from
node-fetch
to the native fetch now available in node, im unsure how to best identify "fetch errors".In
node-fetch
there was such a thing asFetchError
. This is of course not a whatwg fetch spec concept -- just something thatnode-fetch
included as an extension. That said, it was handy because it allowed me to easily determine if something was a "fetch error" by simply evaluatingerror instanceof FetchError
(upon which i could accesserror.code
etc. while keeping TypeScript happy).Using the native
fetch
, errors appear as follows:Could anyone help with the following Qs:
1/ What's the reasoning behind this being a
TypeError
? Feels misleading..2/ Is the best way to identify failed fetches to check
error instanceof TypeError
anderror.message === 'failed fetch'
, and then retrieveerror.cause
?3/ Is there a (internal?) type for
error.cause
? I'm trying to come up with a good (TypeScript-safe) way to get at theerror.type
anderror.code
properties in order to tag my application metrics, and am not sure if there's an existing type that fits the cause (I'm aware of the megathread in DT about having TS types forfetch
but wondering if there's maybe an undici type that is exposed somewhere?)Beta Was this translation helpful? Give feedback.
All reactions