Browse Source

Fix whois-ns-fallback request once again (#143)

try-catch in getNameservers() doesn't work as expected because
a promise is returned succesfully before it's evaluation and
try-catch in the function won't catch if it fails later on.
master
Olli Vanhoja 9 years ago
committed by Guillermo Rauch
parent
commit
2bc5d26fa7
  1. 19
      lib/index.js

19
lib/index.js

@ -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)

Loading…
Cancel
Save