( cause: unknown, method: Dns.DnsError["method"], hostname: string, recordType?: Dns.RecordType )
| 92 | * @since 4.0.0 |
| 93 | */ |
| 94 | export const dnsErrorFromCause = ( |
| 95 | cause: unknown, |
| 96 | method: Dns.DnsError["method"], |
| 97 | hostname: string, |
| 98 | recordType?: Dns.RecordType |
| 99 | ): Dns.DnsError => { |
| 100 | const code = typeof cause === "object" && cause !== null && "code" in cause |
| 101 | ? String(cause.code).replace(/^DNS_/, "") |
| 102 | : undefined |
| 103 | return new Dns.DnsError({ |
| 104 | reason: (code !== undefined ? reasons[code] : undefined) ?? "Unknown", |
| 105 | method, |
| 106 | hostname, |
| 107 | recordType, |
| 108 | cause |
| 109 | }) |
| 110 | } |
| 111 | |
| 112 | // c-ares omits the root dot and represents the root name as an empty string. |
| 113 | const absoluteName = (name: string): string => { |
no test coverage detected