API connection error handling
This commit is contained in:
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user