Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!