API connection error handling

This commit is contained in:
2020-12-07 00:36:36 +01:00
parent de853c4a96
commit 5d34725344
3 changed files with 46 additions and 6 deletions

View File

@@ -2,8 +2,14 @@ import axios from "axios";
export default {
getFruits: async ({ commit }) => {
const response = await axios.get("http://localhost:3000/fruit");
commit("setFruits", response.data.data);
await axios
.get("http://localhost:3000/fruit")
.then(res => {
commit("setFruits", res.data.data);
})
.catch(err => {
if (err.message === "Network Error") throw "Check API connectivity ...";
});
},
getFruit: async ({ commit }, id) => {
const response = await axios.get(`http://localhost:3000/fruit/${id}`);