catch errors and handle gracefully in ENS

This commit is contained in:
VoR0220 2018-06-25 12:25:22 -05:00
parent d12271e85d
commit 1d7851e2ff
1 changed files with 17 additions and 2 deletions

View File

@ -14,6 +14,7 @@ __embarkENS.resolverInterface = [
} }
], ],
"name": "addr", "name": "addr",
"outputs": [ "outputs": [
{ {
"name": "", "name": "",
@ -172,7 +173,14 @@ __embarkENS.resolve = function (name) {
return resolverContract.methods.addr(node).call(); return resolverContract.methods.addr(node).call();
}).then((addr) => { }).then((addr) => {
return addr; return addr;
}).catch(err => err); }).catch((err) => {
if (err == 'Couldn\'t decode addr from ABI: 0x') {
console.log(name + " is not registered");
return "0x";
} else {
return err;
}
});
}; };
__embarkENS.lookup = function (address) { __embarkENS.lookup = function (address) {
@ -189,5 +197,12 @@ __embarkENS.lookup = function (address) {
return self.ens.methods.resolver(node).call().then((resolverAddress) => { return self.ens.methods.resolver(node).call().then((resolverAddress) => {
let resolverContract = new EmbarkJS.Contract({abi: self.resolverInterface, address: resolverAddress}); let resolverContract = new EmbarkJS.Contract({abi: self.resolverInterface, address: resolverAddress});
return resolverContract.methods.name(node).call(); return resolverContract.methods.name(node).call();
}).catch(err => err); }).catch((err) => {
if (err == 'ERROR: The returned value is not a convertible string: 0x0') {
console.log('Address does not resolve to name. Try syncing chain.');
return "";
} else {
return err;
}
});
}; };