Home > Software engineering >  Vue, SPA, Laravel. Erro with response
Vue, SPA, Laravel. Erro with response

Time:05-17

I am getting an error when I request. Оn the backend side there is a check that the name length is at least 3 characters. The response from the server is correct. but when I try to display an error, the message comes out saying that the answer was not found.

async saveBoard(id, index) {
      await this.API.put("/boards/"   id, {
        name: this.boards[index].name,
      })
        .then((response) => {
          alert(response.data.message);
          this.boards[index].etitable = !this.boards[index].etitable;
        })
        .catch((error) => {
          console.log(error);
        });
    },

enter image description here

enter image description here

enter image description here

when I try to output error.response.date to the console, I get an error that response is not defined.

How can I solve this problem, why does axios not see the response from the server and the error code?

CodePudding user response:

Error code must be in your catch You can't reach error message in then.

You are probably see error in your console right now

CodePudding user response:

        return response;
    },
    error => {
        if (error.response.status == 401 || error.response.status == 419) {
            const token = localStorage.getItem('token');
            if (token) {
                localStorage.removeItem('token');
            }

            const user = localStorage.getItem('user');
            if (user) {
                localStorage.removeItem('user');
            }
            router.push('/login');
        } else {
            if (error.response.status == 403) {
                router.push('/');
            }
        }

        
        return Promise.reject(error);
    });```


I added a return to the interceptors function. Problem solved thanks for your help.
  • Related