Catch error number Axios

Asked

Viewed 392 times

0

I’m making a request, which returns me error 401, but I can’t get this number

inserir a descrição da imagem aqui

axios.post(config.urlBase + 'adicionar_empresa', formData)
.then(res => {
  if(res.data){
    this.refs.sucesso.openSucesso(2000);
    this.refs.load.closeLoad();
    this.limparCampos();
  }else{
    this.refs.erro.openErro(3000);
    this.refs.load.closeLoad();
  }
}).catch(e => {
  console.log(e)
});

When I run the code up the console displays this: inserir a descrição da imagem aqui

i believed that in catch he would bring this information but does not bring, anyone knows how I do? I gave a good search and nothing worked for me.

thank you!

  • Try giving a console.log error.response.status

  • I’ve tried that, it doesn’t work... but thanks anyway!

  • That’s too bad. If you don’t have to use Xios take a look at fetch and see if it returns the correct error data...

  • The parameter you receive from catch is an object, and as I recall (I have not tested) e.response.status should give you the error code.

  • @Isac doesn’t work, I’ve tested it

  • @Otaviosouzarocha What results ? And console.log(e.response) gives what ?

  • @Isac I managed to solve, I will post the result

Show 2 more comments

1 answer

0


RESOLUTION: I had to add this line to my . htaccess to enable Cors:

Header set Access-Control-Allow-Origin "*"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.