Created
August 11, 2019 05:34
-
-
Save rintoandrews90/4b0f3373e58d1894ebd136232cd318c9 to your computer and use it in GitHub Desktop.
Error handling in node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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