Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const fetchImpl = require('./lib/web/fetch').fetch
module.exports.fetch = function fetch (resource, init = undefined) {
return fetchImpl(resource, init).catch((err) => {
if (err && typeof err === 'object') {
Error.captureStackTrace(err, this)
Error.captureStackTrace(err)
}
throw err
})
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module.exports.fetch = async function fetch (init, options = undefined) {
return await fetchImpl(init, options)
} catch (err) {
if (err && typeof err === 'object') {
Error.captureStackTrace(err, this)
Error.captureStackTrace(err)
}

throw err
Expand Down
7 changes: 6 additions & 1 deletion test/fetch/client-error-stack-trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

const { test } = require('node:test')
const assert = require('node:assert')
const { fetch } = require('../..')
const { fetch, setGlobalDispatcher, Agent } = require('../..')
const { fetch: fetchIndex } = require('../../index-fetch')

setGlobalDispatcher(new Agent({
headersTimeout: 500,
connectTimeout: 500
}))

test('FETCH: request errors and prints trimmed stack trace', async (t) => {
try {
await fetch('http://a.com')
Expand Down