Skip to content

Instantly share code, notes, and snippets.

@rintoandrews90
Created August 11, 2019 05:34
Show Gist options
  • Save rintoandrews90/4b0f3373e58d1894ebd136232cd318c9 to your computer and use it in GitHub Desktop.
Save rintoandrews90/4b0f3373e58d1894ebd136232cd318c9 to your computer and use it in GitHub Desktop.
Error handling in node.js
const request = require('request')
const url = "https://api.darksky.net/forecast/fb190dafa7914f0bb56e65287631fad9/37.8267,-122.4233"
request({url:url,json:true}, (error,response) => {
if (error) {
console.log('Unable to connect to wheather API')
} else if (response.body.error){
console.log('Error to connect to wheather API')
} else {
console.log('It is currently '+response.body.currently.temperature + ' degress. There is a ' + response.body.currently.precipProbability + ' chance of rain')
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment