From f2b64e4aa26304958464438292c15a0f300d2cdf Mon Sep 17 00:00:00 2001 From: Carlos Fuentes Date: Tue, 17 Dec 2024 09:39:54 +0100 Subject: [PATCH 1/2] fix(3951): typo on errorede dns lookup --- lib/interceptor/dns.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/interceptor/dns.js b/lib/interceptor/dns.js index fc5dc1a4366..513a6e1f7df 100644 --- a/lib/interceptor/dns.js +++ b/lib/interceptor/dns.js @@ -349,7 +349,7 @@ module.exports = interceptorOpts => { instance.runLookup(origin, origDispatchOpts, (err, newOrigin) => { if (err) { - return handler.onError(err) + return handler.onResponseError(null, err) } let dispatchOpts = null From 656c9da8d2fc57251bf81ca669105b18923d25a3 Mon Sep 17 00:00:00 2001 From: Carlos Fuentes Date: Wed, 18 Dec 2024 10:23:19 +0100 Subject: [PATCH 2/2] test: add testing --- test/interceptors/dns.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/interceptors/dns.js b/test/interceptors/dns.js index 944c190492e..436a81e6af2 100644 --- a/test/interceptors/dns.js +++ b/test/interceptors/dns.js @@ -1814,3 +1814,28 @@ test('#3937 - Handle host correctly', async t => { t.equal(response2.statusCode, 200) t.equal(await response2.body.text(), 'hello world!') }) + +test('#3951 - Should handle lookup errors correctly', async t => { + const suite = tspl(t, { plan: 1 }) + + const requestOptions = { + method: 'GET', + path: '/', + headers: { + 'content-type': 'application/json' + } + } + + const client = new Agent().compose([ + dns({ + lookup: (_origin, _opts, cb) => { + cb(new Error('lookup error')) + } + }) + ]) + + suite.rejects(client.request({ + ...requestOptions, + origin: 'http://localhost' + }), new Error('lookup error')) +})