Skip to content
This repository has been archived by the owner on Nov 27, 2019. It is now read-only.

Catch unhandled errors. #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 46 additions & 42 deletions rsk-faucet.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,71 +226,75 @@ const rns = web3.eth.contract([
]).at('0xeff983147ae97758c04f65ac7dee7c7cacf48ba2')

app.post('/', function (req, res) {
const reqValue = req.body.rskAddress;
try {
const reqValue = req.body.rskAddress;


if (isRNS(reqValue)) {
const hash = namehash(reqValue);
rns.resolver(hash, (err, resolverAddress) => {
if (err) return res.status(400).send('RNS error.');
if (isRNS(reqValue)) {
const hash = namehash(reqValue);
rns.resolver(hash, (err, resolverAddress) => {
if (err) return res.status(400).send('RNS error.');

if (resolverAddress === '0x0000000000000000000000000000000000000000') return res.status(400).send('No address resolution found.');
if (resolverAddress === '0x0000000000000000000000000000000000000000') return res.status(400).send('No address resolution found.');

const resolver = web3.eth.contract([
{
"constant": true,
"inputs": [
const resolver = web3.eth.contract([
{
"name": "interfaceID",
"type": "bytes4"
}
],
"name": "supportsInterface",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "pure",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "node",
"type": "bytes32"
"name": "interfaceID",
"type": "bytes4"
}
],
"name": "addr",
"name": "supportsInterface",
"outputs": [
{
"name": "",
"type": "address"
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"stateMutability": "pure",
"type": "function"
}
]).at(resolverAddress);
},
{
"constant": true,
"inputs": [
{
"name": "node",
"type": "bytes32"
}
],
"name": "addr",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]).at(resolverAddress);

resolver.supportsInterface('0x3b3b57de', (err, result) => {
if (err || !result) return res.status(400).send('No address resolution found.');
resolver.supportsInterface('0x3b3b57de', (err, result) => {
if (err || !result) return res.status(400).send('No address resolution found.');

resolver.addr(hash, (err, addr) => {
if (err) return res.status(400).send('RNS error.');
resolver.addr(hash, (err, addr) => {
if (err) return res.status(400).send('RNS error.');

console.log(addr)
console.log(addr)

return executeDispense(req, res, addr.toLowerCase());
return executeDispense(req, res, addr.toLowerCase());
})
})
})
})
} else {
executeDispense(req, res, reqValue);
} else {
executeDispense(req, res, reqValue);
}
} catch {
return res.status(400).send('An error occurred, try again later.');
}
});

Expand Down