File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,20 +41,24 @@ const LB_REPLICA_SET_ERROR = 'loadBalanced option not supported with a replicaSe
4141const LB_DIRECT_CONNECTION_ERROR =
4242 'loadBalanced option not supported when directConnection is provided' ;
4343
44- function retryDNSTimeoutFor ( rrtype : 'SRV' ) : ( a : string ) => Promise < dns . SrvRecord [ ] > ;
45- function retryDNSTimeoutFor ( rrtype : 'TXT' ) : ( a : string ) => Promise < string [ ] [ ] > ;
46- function retryDNSTimeoutFor (
47- rrtype : 'SRV' | 'TXT'
48- ) : ( a : string ) => Promise < dns . SrvRecord [ ] | string [ ] [ ] > {
44+ // connect the rrtype to the expected result
45+ interface DNSLookupMap {
46+ SRV : dns . SrvRecord [ ] ;
47+ TXT : string [ ] [ ] ;
48+ }
49+ function retryDNSTimeoutFor < T extends keyof DNSLookupMap > (
50+ rrtype : T
51+ ) : ( lookupAddress : string ) => Promise < DNSLookupMap [ T ] > {
4952 return async function dnsReqRetryTimeout ( lookupAddress : string ) {
53+ const resolve = ( ) => dns . promises . resolve ( lookupAddress , rrtype ) as Promise < DNSLookupMap [ T ] > ;
54+
5055 try {
51- return ( await dns . promises . resolve ( lookupAddress , rrtype ) ) as dns . SrvRecord [ ] | string [ ] [ ] ;
56+ return await resolve ( ) ;
5257 } catch ( firstDNSError ) {
53- if ( firstDNSError . code === dns . TIMEOUT ) {
54- return ( await dns . promises . resolve ( lookupAddress , rrtype ) ) as dns . SrvRecord [ ] | string [ ] [ ] ;
55- } else {
56- throw firstDNSError ;
58+ if ( firstDNSError . code === 'ETIMEOUT' ) {
59+ return await resolve ( ) ;
5760 }
61+ throw firstDNSError ;
5862 }
5963 } ;
6064}
You can’t perform that action at this time.
0 commit comments