Skip to content

Commit

Permalink
fix: aborting request with non-object error (nodejs#2243)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and crysmags committed Feb 27, 2024
1 parent ab30efa commit 5ae801c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ if (util.nodeMajor > 16 || (util.nodeMajor === 16 && util.nodeMinor >= 8)) {
try {
return await fetchImpl(...arguments)
} catch (err) {
Error.captureStackTrace(err, this)
if (typeof err === 'object') {
Error.captureStackTrace(err, this)
}

throw err
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/fetch/issue-2242.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict'

const { test } = require('tap')
const { fetch } = require('../..')

test('fetch with signal already aborted', async (t) => {
await t.rejects(fetch('http://localhost', { signal: AbortSignal.abort('Already aborted') }), 'Already aborted')
})

0 comments on commit 5ae801c

Please sign in to comment.