UNPKG

@azure/core-amqp

Version:

Common library for amqp based azure sdks like @azure/event-hubs.

28 lines 1.27 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import { CONNREFUSED, TIMEOUT, resolve as dnsResolve } from "node:dns"; import { logger } from "../log.js"; /** * Checks whether a network connection is detected. * @internal */ export function checkNetworkConnection(host) { return new Promise((resolve) => { logger.verbose("Calling dns.resolve to determine network connection status."); dnsResolve(host, function (err) { if (err) { logger.verbose("Error thrown from dns.resolve in network connection check: '%s', %O", err.code || err.name, err); // List of possible DNS error codes: https://nodejs.org/dist/latest-v12.x/docs/api/dns.html#dns_error_codes // We only resolve with `false` when dnsResolve fails with an error we expect to see when the network is down. if (err.code === CONNREFUSED || err.code === TIMEOUT) { return resolve(false); } } else { logger.verbose("Successfully resolved host via dns.resolve in network connection check."); } return resolve(true); }); }); } //# sourceMappingURL=checkNetworkConnection.js.map