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 8 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 } = {}) {
try {
return this.retry(async (bail, attempt) => {
getNameservers (domain) {
return new Promise((resolve, reject) => {
let fallback = false;
this.retry(async (bail, attempt) => {
if (this._debug) console.time(`> [debug] #${attempt} GET /whois-ns${fallback ? '-fallback' : ''}`);
const res = await this._fetch(`/whois-ns${fallback ? '-fallback' : ''}?domain=${encodeURIComponent(domain)}`);
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 the nameservers are `null` it's likely
// that our whois service failed to parse it
return this.getNameservers(domain, { fallback: true });
fallback = true;
throw new Error('Invalid whois response');
}
return body;
} else {
if (attempt > 1) fallback = true;
throw new Error(`Whois error (${res.status}): ${body.error.message}`);
}
});
} catch (err) {
if (fallback) throw err;
return this.getNameservers(domain, { fallback: true });
}
}).then((body) => resolve(body));
});
}
// _ensures_ the domain is setup (idempotent)

Loading…
Cancel
Save