How to catch net::ERR_CONNECTION_REFUSED in Vue.js with axios

Here is my Get request code : loadProducts({ commit }) { setTimeout(() => { axios … Read more How to catch net::ERR_CONNECTION_REFUSED in Vue.js with axios

Here is my Get request code :

    loadProducts({ commit }) {
      setTimeout(() => {
        axios
          .get(`${process.env.VUE_APP_BACKEND_URL}/home/touristic_places`)
          .then((res) => commit("setPlaces", res.data))
          .catch((err) => console.error(err));
      }, 1000);
      setTimeout(() => {
        axios
          .get(`${process.env.VUE_APP_BACKEND_URL}/home/hotels`)
          .then((res) => commit("setHotels", res.data))
          .catch((err) => console.error(err));
      }, 1000);
      setTimeout(() => {
        axios
          .get(`${process.env.VUE_APP_BACKEND_URL}/home/restaurants`)
          .then((res) => commit("setRestaurants", res.data))
          .catch((err) => console.error(err));
      }, 1000);
    },

But when my server is offline my code just throws net::ERR_CONNECTION_REFUSED. Is there a way to handle this error and let the front-end user know that the server is currently offline?

here is where i call the functions

  mounted() {
    this.$store.dispatch("loadProducts");
  },

Source: Vue – Stack Overflow



Leave a Reply

Your email address will not be published. Required fields are marked *