January 2018
Beginner
658 pages
13h 10m
English
Now we do want to add a little error handling inside of our callback function. We'll handle errors on the error object, and we'll also handle errors that come back from the forecast.io servers. First up, just like we did for the geocoding API, we'll check if error exists. If it does, that means that we were unable to connect to the servers, so we can print a message that relays that message to the user, console.log something like Unable to connect to forecast.io server.:
request({ url: 'https://api.forecast.io/forecast/4a04d1c42fd9d32c97a2c291a32d5e2d/39.9396284,-75.18663959999999', json: true}, (error, response, body) => { if (error){ console.log('Unable to connect to Forecast.io server.'); }