Skip to content

Commit f4f2b03

Browse files
authoredJan 4, 2024
fix(dns): fixed lookup error handling; (#6175)
1 parent 1f73dcb commit f4f2b03

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
 

‎lib/adapters/http.js

+4
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
171171
// hotfix to support opt.all option which is required for node 20.x
172172
lookup = (hostname, opt, cb) => {
173173
_lookup(hostname, opt, (err, arg0, arg1) => {
174+
if (err) {
175+
return cb(err);
176+
}
177+
174178
const addresses = utils.isArray(arg0) ? arg0.map(addr => buildAddressEntry(addr)) : [buildAddressEntry(arg0, arg1)];
175179

176180
opt.all ? cb(err, addresses) : cb(err, addresses[0].address, addresses[0].family);

‎test/unit/adapters/http.js

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import util from 'util';
99
import assert from 'assert';
1010
import fs from 'fs';
1111
import path from 'path';
12+
import {lookup} from 'dns';
1213
let server, proxy;
1314
import AxiosError from '../../../lib/core/AxiosError.js';
1415
import FormDataLegacy from 'form-data';
@@ -2216,5 +2217,13 @@ describe('supports http with nodejs', function () {
22162217

22172218
assert.strictEqual(data, payload);
22182219
});
2220+
2221+
it('should handle errors', () => {
2222+
return assert.rejects(async () => {
2223+
await axios.get('https://no-such-domain-987654.com', {
2224+
lookup
2225+
});
2226+
}, /ENOTFOUND/);
2227+
});
22192228
});
22202229
});

0 commit comments

Comments
 (0)
Please sign in to comment.