diff --git a/.changeset/gold-impalas-think.md b/.changeset/gold-impalas-think.md new file mode 100644 index 0000000..5fb2ec8 --- /dev/null +++ b/.changeset/gold-impalas-think.md @@ -0,0 +1,5 @@ +--- +'fetch-nodeshim': patch +--- + +Issue an explicit `ETIMEDOUT` when the request times out diff --git a/src/fetch.ts b/src/fetch.ts index 2825bbd..338b506 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -160,6 +160,14 @@ async function _fetch( signal?.addEventListener('abort', destroy); + outgoing.on('timeout', () => { + if (!incoming) { + const error = new Error('Request timed out') as NodeJS.ErrnoException; + error.code = 'ETIMEDOUT'; + destroy(error); + } + }); + outgoing.on('response', _incoming => { if (signal?.aborted) { return;