Skip to content

Commit

Permalink
fix(dns): fixed lookup error handling; (#6175)
Browse files Browse the repository at this point in the history
  • Loading branch information
DigitalBrainJS authored Jan 4, 2024
1 parent 1f73dcb commit f4f2b03
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/adapters/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
// hotfix to support opt.all option which is required for node 20.x
lookup = (hostname, opt, cb) => {
_lookup(hostname, opt, (err, arg0, arg1) => {
if (err) {
return cb(err);
}

const addresses = utils.isArray(arg0) ? arg0.map(addr => buildAddressEntry(addr)) : [buildAddressEntry(arg0, arg1)];

opt.all ? cb(err, addresses) : cb(err, addresses[0].address, addresses[0].family);
Expand Down
9 changes: 9 additions & 0 deletions test/unit/adapters/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import util from 'util';
import assert from 'assert';
import fs from 'fs';
import path from 'path';
import {lookup} from 'dns';
let server, proxy;
import AxiosError from '../../../lib/core/AxiosError.js';
import FormDataLegacy from 'form-data';
Expand Down Expand Up @@ -2216,5 +2217,13 @@ describe('supports http with nodejs', function () {

assert.strictEqual(data, payload);
});

it('should handle errors', () => {
return assert.rejects(async () => {
await axios.get('https://no-such-domain-987654.com', {
lookup
});
}, /ENOTFOUND/);
});
});
});

0 comments on commit f4f2b03

Please sign in to comment.