mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
fix(dns): fixed lookup error handling; (#6175)
This commit is contained in:
@@ -171,6 +171,10 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|||||||
// hotfix to support opt.all option which is required for node 20.x
|
// hotfix to support opt.all option which is required for node 20.x
|
||||||
lookup = (hostname, opt, cb) => {
|
lookup = (hostname, opt, cb) => {
|
||||||
_lookup(hostname, opt, (err, arg0, arg1) => {
|
_lookup(hostname, opt, (err, arg0, arg1) => {
|
||||||
|
if (err) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
|
||||||
const addresses = utils.isArray(arg0) ? arg0.map(addr => buildAddressEntry(addr)) : [buildAddressEntry(arg0, arg1)];
|
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);
|
opt.all ? cb(err, addresses) : cb(err, addresses[0].address, addresses[0].family);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import util from 'util';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import {lookup} from 'dns';
|
||||||
let server, proxy;
|
let server, proxy;
|
||||||
import AxiosError from '../../../lib/core/AxiosError.js';
|
import AxiosError from '../../../lib/core/AxiosError.js';
|
||||||
import FormDataLegacy from 'form-data';
|
import FormDataLegacy from 'form-data';
|
||||||
@@ -2216,5 +2217,13 @@ describe('supports http with nodejs', function () {
|
|||||||
|
|
||||||
assert.strictEqual(data, payload);
|
assert.strictEqual(data, payload);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle errors', () => {
|
||||||
|
return assert.rejects(async () => {
|
||||||
|
await axios.get('https://no-such-domain-987654.com', {
|
||||||
|
lookup
|
||||||
|
});
|
||||||
|
}, /ENOTFOUND/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user