When the function below executed I am getting an error stating:
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 362): TypeError: request(...).then is not a function
I am not aware of the reasoning for this error message, though I assume it has something to do with my request. According the to the documentation for "request-promise" my code if formatted correctly.
const request = require('request-promise');
addressFunction(lat,lon){
var error = "No Address Data"
var addressExist = true;
return new Promise(
function(resolve){
if(addressExist) {
let apiKey = "API-Key";
let geocodeAddress = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lon + "&key=" + apiKey;
resolve(
request(geocodeAddress).then(res => {
res = JSON.parse(res);
newAddress = res.results[0].formatted_address.replace(/^\d+\s*/, '');
newAddress = newAddress.split(',', 3).join(',').replace(/[0-9]/g, '').trim()
return newAddress
})
);
}
}
);
} }
I've tried passing in an "options" argument such as
var options = {
uri: 'http://www.google.com',
transform: function (body) {
return cheerio.load(body);
}
Though that still did not work.
Anyone have an idea of why the request...then is throwing errors?