lamed_learn
Version:
Learning through code templates
26 lines (24 loc) • 856 B
JavaScript
// Setup Search string --------------------
let searchStr = {
url: `https://????...${address}`,
json: true
}
// Request --------------------------------------
_log(`Searching for "${address}"...`)
request(searchStr, (error, response, body) => {
// Check for errors -------------------------
if (error || response.statusCode !== 200) {
let searchStr = JSON.stringify(searchStr, undefined, 2)
reject(`Error! Unable to to connect to server. \n Code: '${response.statusCode};\n Search str:${searchStr} \n ${error}`)
} else {
// _logJSON(body);
let result = body.results[0]
if (body.status !== 'OK') {
reject(`Error! Return status is '${body.status}'.`)
return false
}
// Result ------------------------------
resolve(result)
}
})
// ---------------------------------------------