Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda