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,24 +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- // 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 ] > {
44+ function retryDNSTimeoutFor ( rrtype : 'SRV' ) : ( lookupAddress : string ) => Promise < dns . SrvRecord [ ] > ;
45+ function retryDNSTimeoutFor ( rrtype : 'TXT' ) : ( lookupAddress : string ) => Promise < string [ ] [ ] > ;
46+ function retryDNSTimeoutFor (
47+ rrtype : 'SRV' | 'TXT'
48+ ) : ( lookupAddress : string ) => Promise < dns . SrvRecord [ ] | string [ ] [ ] > {
49+ const resolve =
50+ rrtype === 'SRV'
51+ ? ( address : string ) => dns . promises . resolve ( address , 'SRV' )
52+ : ( address : string ) => dns . promises . resolve ( address , 'TXT' ) ;
5253 return async function dnsReqRetryTimeout ( lookupAddress : string ) {
53- const resolve = ( ) => dns . promises . resolve ( lookupAddress , rrtype ) as Promise < DNSLookupMap [ T ] > ;
54-
5554 try {
56- return await resolve ( ) ;
55+ return await resolve ( lookupAddress ) ;
5756 } catch ( firstDNSError ) {
58- if ( firstDNSError . code === 'ETIMEOUT' ) {
59- return await resolve ( ) ;
57+ if ( firstDNSError . code === dns . TIMEOUT ) {
58+ return await resolve ( lookupAddress ) ;
59+ } else {
60+ throw firstDNSError ;
6061 }
61- throw firstDNSError ;
6262 }
6363 } ;
6464}
You can’t perform that action at this time.
0 commit comments