Skip to content

Commit

Permalink
fix: non-object error in abort throws bad error
Browse files Browse the repository at this point in the history
  • Loading branch information
atlowChemi committed Jan 7, 2024
1 parent 62278d5 commit e093856
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const fetchImpl = require('./lib/fetch').fetch

module.exports.fetch = function fetch (resource, init = undefined) {
return fetchImpl(resource, init).catch((err) => {
Error.captureStackTrace(err, this)
if (typeof err === 'object') {
Error.captureStackTrace(err, this)
}
throw err
})
}
Expand Down
10 changes: 10 additions & 0 deletions test/fetch/issue-2242.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { test } = require('node:test')
const assert = require('node:assert')
const { fetch } = require('../..')
const nodeFetch = require('../../index-fetch')

test('fetch with signal already aborted', async () => {
await assert.rejects(
Expand All @@ -12,3 +13,12 @@ test('fetch with signal already aborted', async () => {
/Already aborted/
)
})

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

0 comments on commit e093856

Please sign in to comment.