Skip to content

Commit 3eeeeb7

Browse files
authored
fix(3951): typo on errorede dns lookup (nodejs#3956)
* fix(3951): typo on errorede dns lookup * test: add testing
1 parent 29760e7 commit 3eeeeb7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/interceptor/dns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ module.exports = interceptorOpts => {
353353

354354
instance.runLookup(origin, origDispatchOpts, (err, newOrigin) => {
355355
if (err) {
356-
return handler.onError(err)
356+
return handler.onResponseError(null, err)
357357
}
358358

359359
let dispatchOpts = null

test/interceptors/dns.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,3 +1865,28 @@ test('#3937 - Handle host correctly', async t => {
18651865
t.equal(response2.statusCode, 200)
18661866
t.equal(await response2.body.text(), 'hello world!')
18671867
})
1868+
1869+
test('#3951 - Should handle lookup errors correctly', async t => {
1870+
const suite = tspl(t, { plan: 1 })
1871+
1872+
const requestOptions = {
1873+
method: 'GET',
1874+
path: '/',
1875+
headers: {
1876+
'content-type': 'application/json'
1877+
}
1878+
}
1879+
1880+
const client = new Agent().compose([
1881+
dns({
1882+
lookup: (_origin, _opts, cb) => {
1883+
cb(new Error('lookup error'))
1884+
}
1885+
})
1886+
])
1887+
1888+
suite.rejects(client.request({
1889+
...requestOptions,
1890+
origin: 'http://localhost'
1891+
}), new Error('lookup error'))
1892+
})

0 commit comments

Comments
 (0)