A
A
Alexander Koregin2020-04-22 16:59:16
Vue.js
Alexander Koregin, 2020-04-22 16:59:16

Why does catch work?

I'm trying to make authorization, if I enter the wrong login and password, then catch gives an error correctly, and if I enter everything correctly, then catch gives an error

YzGIBSVzD4E.jpg

Code:

methods: {
    async auth() {
      if (this.password != "" || this.login != "") {
        axios
          .post("http://localhost/polls/public/api/login", {
            login: this.login,
            password: this.password
          })
          .then(response => {
            if (response.status == 200) {
              this.$store.commit("login", response.data);
              this.$router.push("/main");
            }
          })
          .catch(error => {
            if (error.response.status == 404) {
              this.textModal = "Неправильно указан логин или пароль";
              this.openModal = true;
              setTimeout(() => (this.openModal = false), 2000);
            }
          });
      } else {
        this.textModal = "Введите все данные!";
        this.openModal = true;
        setTimeout(() => (this.openModal = false), 2000);
      }
    }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2020-04-22
@dragonika8

If the network is down, then the response will have no status. Or the exception itself is not from axios, but, for example, from the line If I understand correctly, then it swears at in any case, you can always insert console.log () since the browser debugger with a stop by mistake or just with breakpoints cannot be forced to use .
this.$store.commit("login", response.data);
if (error.response.status == 404) {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question