Skip to content

Commit

Permalink
Synthesize rdap error result for 'Multiple country' errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NetBlocks Team committed Sep 3, 2018
1 parent 20a19f1 commit 7fc382a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fetch-rdap.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,25 @@ function query (ip) {
return axios.get(query_url, {
// TODO: Make timeout configurable
timeout: 2500,
validateStatus: false,
headers: {
'Accept': 'application/rdap+json'
}
})
.then(function (res) {
if (res.status === 400) {
// https://github.com/arineng/nicinfo/issues/21
var m = res.data.title.match(/^Multiple country: found in (.*) - (.*)$/);
if (m) {
return {rdap: {
errorCode: res.status,
ipVersion: /^[\d.]+$/.test(m[1]) ? 'v4' : 'v6',
startAddress: m[1],
endAddress: m[2],
...res.data,
}};
}
}
if (res.status != 200)
throw new Error('Invalid HTTP status: ' + res.status);
return {rdap: res.data};
Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ async function testStability (range) {
*/
}

/*
// TODO: test error synthesis
// https://github.com/arineng/nicinfo/issues/21
// https://rdap.db.ripe.net/ip/81.92.203.83
*/

async function testBasic () {
var res;
res = await whois.check(ips_ipv4[0]);
Expand Down

0 comments on commit 7fc382a

Please sign in to comment.