Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

326
Visualizações
Uncaught (in promise) Error: Network Error at createError

I'm going to use Axios to communicate API. But that kind of error keeps coming out. I don't understand this problem. I searched on the Internet and tried everything. Help me. All I want is to click on that button to see the low value in the developer tool.

  useEffect(() => {
    setJwt(getClientCookieFromClient('jwt'));
  }, []);

  const customFetch = async () => {
    const res = await axios
      .get(`${process.env.NEXT_PUBLIC_WECODE_URI}/subscription/master_table`, {
        headers: {
          Authentication: jwt,
        },
      })
      .then((res) => res.data);
    if (!res.data.success) {
      alert(res.data.message);
    }
  };

...

<button onClick={() => customFetch()}>API호출버튼</button>
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Note:

not sure about you response structure. Current code works as expected for structure:

res = { data: { data: {success: true}}}

if it is not so, then use if statement as !res.success


useEffect(() => {
    setJwt(getClientCookieFromClient('jwt'));
  }, []);

  const customFetch = async () => {
    const res = await axios
      .get(`${process.env.NEXT_PUBLIC_WECODE_URI}/subscription/master_table`, {
        headers: {
          Authentication: jwt,
        },
      })
      .then((res) => res.data)
      .catch((err) => console.log("Error while fetching",err)); //<--- use .catch for catching error
    if (!res.data.success) {
      alert(res.data.message);
    }
  };
about 4 years ago · Juan Pablo Isaza Relatório

0

Alway wrap await inside try/catch block.

const customFetch = async () => {
  try {
    const res = await axios
      .get(`${process.env.NEXT_PUBLIC_WECODE_URI}/subscription/master_table`, {
        headers: {
          Authentication: jwt,
        },
      })
      .then((res) => res.data);
    if (!res.data.success) {
      alert(res.data.message);
    }
  } catch (error) {
    console.log(error);
    // Do something with error
  }
};
about 4 years ago · Juan Pablo Isaza Relatório

0

Try

useEffect(() => {
  setJwt(getClientCookieFromClient('jwt'));
}, []);

const customFetch = async () => {
  const res = await axios.get(`${process.env.NEXT_PUBLIC_WECODE_URI}/subscription/master_table`, {
    headers: {
      Authentication: jwt,
    },
  });
  if (!res.data.success) {
    alert(res.data.message);
  }
};

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda