January 2018
Beginner
658 pages
13h 10m
English
Now aside from the success handler we used in the previous example, we can also add a call to catch, to let us catch all of the errors that might occur. We'll to get the error object as the one-and-only argument; then we can do something with that error object:
axios.get(geocodeUrl).then((response) => { console.log(response.data);});catch((e) => {});
Inside the function, we'll kick things off, using console.log to print the error argument:
}).catch((e) => { console.log(e)});
Now let's simulate an error by removing the dot in the URL:
var encodedAddress = encodeURIComponent(argv.address);var geocodeUrl = `https://mapsgoogleapis.com/maps/api/geocode/json?address=${encodedAddress}`;axios.get(geocodeUrl).then((response) ...Read now
Unlock full access