Skip to content

Instantly share code, notes, and snippets.

@abel-masila
Created April 24, 2018 11:16
Show Gist options
  • Save abel-masila/66f049d305af62e0a82b5dfa3d1535d1 to your computer and use it in GitHub Desktop.
Save abel-masila/66f049d305af62e0a82b5dfa3d1535d1 to your computer and use it in GitHub Desktop.
axios.get(geocodeURL).then((response)=>{
if(response.data.status==='ZERO_RESULTS'){
throw new Error('Unable to find that address!');
}
const lat=response.data.results[0].geometry.location.lat;
const lng=response.data.results[0].geometry.location.lng;
const weatherURL=`https://api.darksky.net/forecast/3708bcb6e2a477e7fb94de8fd3ecdfab/${lat},${lng}`;
console.log(response.data.results[0].formatted_address);
//chain promises to get weather data
return axios.get(weatherURL);
}).then((response)=>{
const temperature=response.data.currently.temperature;
const apparentTemperature=response.data.currently.apparentTemperature;
console.log(`it's currently ${temperature}. It feels like ${apparentTemperature}`);
})
.catch((error)=>{
if(error.code==='ENOTFOUND'){
console.log('Unable to connect api service');
} else {
console.log(error.message);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment