title: Global error handling using axios in vuejs
body: <p>I am using axios in vuejs and have a trouble with global error handling while axios call. I'm trying as follow and it not only takes user logout but also executes the code block after the axios call.
    How can I prevent the execution of the axios call promise code section if error occurs.</p>
  
  <pre><code>export default {
      created() {
      var self = this;
        if (self.$route.meta.requiresAuth) {
          axios.interceptors.response.use(
            function(response) {
              return response;
            },
            function(error) {
              if (error.response.status == 401) {
                self.$toaster.error("ERROR: Invalid token detected");
                  self.logout();
                }
              }
            );
          }
        },
        methods: {
          logout() {
            this.$router.push({ name: "login" });
          }
        }
      }
  
  someFunction() {
    var self = this;
    axios
      .post(
        "url/to/api",
        {},
        {
          headers: {
            Authorization: "authtoken here"
          }
        }
      )
      .then(response =&gt; {
        alert("success");
          otherFunction();
        })
        .catch(error =&gt; {
          console.log(error);
        });
  }
  </code></pre>