Skip to content

Commit

Permalink
fix: forward error reason to fetch controller
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed Jun 26, 2023
1 parent 23e62c4 commit ac82a53
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async function fetch (input, init = {}) {

// 3. If controller is not null, then abort controller.
if (controller != null) {
controller.abort()
controller.abort(requestObject.signal.reason)
}
},
{ once: true }
Expand Down
24 changes: 24 additions & 0 deletions test/fetch/issue-2171.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict'

const { fetch } = require('../..')
const { once } = require('events')
const { createServer } = require('http')
const { test } = require('tap')

test('error reason is forwarded - issue #2171', { skip: !AbortSignal.timeout }, async (t) => {
const server = createServer(() => {}).listen(0)

t.teardown(server.close.bind(server))
await once(server, 'listening')

const timeout = AbortSignal.timeout(100)
await t.rejects(
fetch(`http://localhost:${server.address().port}`, {
signal: timeout
}),
{
name: 'TimeoutError',
code: DOMException.TIMEOUT_ERR
}
)
})

0 comments on commit ac82a53

Please sign in to comment.