Axios Uncaught (in promise) Error: Request failed with status code 404

Viewed 4414

I need to send data to backend, but I am having this error:

Uncaught (in promise) Error: Request failed with status code 404

How can I solve this??

Image below:

error

Code javascript below:

handleClick(_success, _error) {
    const usuarioLogin = this.props.cliente;
    const usuarioCliente = parseInt(this.state.usuario);

    const ObjetoChamado = {
      titulo: this.state.titulo,
      descricao: this.state.descricao,
      area: parseInt(this.state.area),
      categoria: parseInt(this.state.categoria),
      servico: parseInt(this.state.servico),
      usuario: usuarioLogin,
      cliente: usuarioCliente,
    };

    this.props.abrirChamado(
      ObjetoChamado,
      (response) => {
        this.props.getChamados(usuarioLogin, null, (chamados) => {
          // Chamado aberto, atualizar lista e fechar o popup de abertura
          this.props.setClientData(usuarioLogin, null, chamados.data.objeto);
          this.props.visible(false);
        });
      },
      (error) => {
        alert(!!error ? error : 'Não foi possível abrir o chamado.');
      }
    );

    axios.post(ObjetoChamado).then((response) => {
      const data = response.data;

      //   if (Object.keys(data).length > 0) {
      //     if (typeof _success === 'function') _success(data);
      //   } else {
      //     if (typeof _error === 'function') {
      //       _error({
      //         code: 404,
      //         message: 'Não há nenhum registro para este cliente.',
      //       });
      //     }
      //   }
      console.log('DATA:', data);
    });
  };
1 Answers

status code 404 means that the API path that you have provided in the axios is not valid. So you need to check the API path.

axios.post(ObjetoChamado) - this is wrong.

You need to pass two arguments to axios.post, first one would the API path at which you want to send the data and second argument would be the data object. SO your code would look something like this -

axios.post('/your-api-path', objectoChamado).then(response => {

});

Related