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

206
Visualizações
JS throws an error on response.data on mobile phones

I encountered a problem where everything is properly working on pc, but on mobile phone, it is a different story. When the request is done on pc, it alerts the user on the screen that: "Name is required." and so on (I did not fill name or other properties in purpose). However, when this time I try it on mobile phone, it throws me an error that Cannot read properties of undefined (reading 'data') and gives reference to the line const data = await err.response.data;

There is a code snippet:

    try {
      const config = {
        headers: {
          "Context-Type": "application/json",
        },
      };

      const res = await axios.post(
        USERS_PATH,
        {
          name,
          surname,
          email,
          password,
          repeatedPassword,
        },
        config
      );
      console.log(res.data);
    } catch (err) {
      const data = await err.response.data;
      userCtx.updateAlertMessage(Object.values(data).flat());
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It should crush regardless of the platform. To fix it, check if the response is null before accessing the data. You can do it using the ? null checker.

Modified line: const data = await err.response?.data;

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