Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch: fix captureStackTrace #3227

Merged
merged 2 commits into from
May 10, 2024
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
Loading