@ -364,9 +364,11 @@ export default class Now extends EventEmitter {
} ) ;
} ) ;
}
}
getNameservers ( domain , { fallback = false } = { } ) {
getNameservers ( domain ) {
try {
return new Promise ( ( resolve , reject ) => {
return this . retry ( async ( bail , attempt ) => {
let fallback = false ;
this . retry ( async ( bail , attempt ) => {
if ( this . _ debug ) console . time ( ` > [debug] # ${ attempt } GET /whois-ns ${ fallback ? '-fallback' : '' } ` ) ;
if ( this . _ debug ) console . time ( ` > [debug] # ${ attempt } GET /whois-ns ${ fallback ? '-fallback' : '' } ` ) ;
const res = await this . _ fetch ( ` /whois-ns ${ fallback ? '-fallback' : '' } ?domain= ${ encodeURIComponent ( domain ) } ` ) ;
const res = await this . _ fetch ( ` /whois-ns ${ fallback ? '-fallback' : '' } ?domain= ${ encodeURIComponent ( domain ) } ` ) ;
if ( this . _ debug ) console . timeEnd ( ` > [debug] # ${ attempt } GET /whois-ns ${ fallback ? '-fallback' : '' } ` ) ;
if ( this . _ debug ) console . timeEnd ( ` > [debug] # ${ attempt } GET /whois-ns ${ fallback ? '-fallback' : '' } ` ) ;
@ -375,18 +377,17 @@ export default class Now extends EventEmitter {
if ( ( ! body . nameservers || body . nameservers . length === 0 ) && ! fallback ) {
if ( ( ! body . nameservers || body . nameservers . length === 0 ) && ! fallback ) {
// if the nameservers are `null` it's likely
// if the nameservers are `null` it's likely
// that our whois service failed to parse it
// that our whois service failed to parse it
return this . getNameservers ( domain , { fallback : true } ) ;
fallback = true ;
throw new Error ( 'Invalid whois response' ) ;
}
}
return body ;
return body ;
} else {
} else {
if ( attempt > 1 ) fallback = true ;
throw new Error ( ` Whois error ( ${ res . status } ): ${ body . error . message } ` ) ;
throw new Error ( ` Whois error ( ${ res . status } ): ${ body . error . message } ` ) ;
}
}
} ) ;
} ) . then ( ( body ) => resolve ( body ) ) ;
} catch ( err ) {
} ) ;
if ( fallback ) throw err ;
return this . getNameservers ( domain , { fallback : true } ) ;
}
}
}
// _ensures_ the domain is setup (idempotent)
// _ensures_ the domain is setup (idempotent)