Skip to content

Commit

Permalink
fetch: fix captureStackTrace (#3227)
Browse files Browse the repository at this point in the history
* fetch: fix captureStackTrace

* improve test case performance
  • Loading branch information
Uzlopak committed May 10, 2024
1 parent a613753 commit 0a64b44
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
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

0 comments on commit 0a64b44

Please sign in to comment.