Start your All-Access Pass to unlock this challenge
In this section, we learned that you can wrap any AJAX call in a try...catch
to catch any errors that may arise during that AJAX call. We also say that we
should limit that try...catch
to just the statement that performs the call.
Here's an example:
async created() {
this.loading = true;
let response;
try {
response = await axios.get('/api/get-turtle');
} catch(e) {
this.loading = false;
return;
}
this.loading = false;
this.products = response.data;
},
Why is it important that the try...catch
only includes the AJAX call?