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

133
Views
Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'error')
const getToken = (userId, token) => {
  22 |   getmeToken(userId, token).then((info) => {
  23 |     console.log("INFO COMING", info);
> 24 |     if (info.error) {
  25 |      setInfo({ ...info, error: info.error });
  26 |     } else {
  27 |       const clientToken = info.clientToken;

What is meant by Unhandled rejection, cannot read properties of undefined??.

I have defined the error and also assigned a value for it, below is the code of useState

  const [info, setInfo] = useState({
    loading: false,
    success: false,
    clientToken: null,
    error:"",
    instance: {},
  });

As per the above code, I have defined and assigned the value for error, then why is the browser still showing cannot read properties of undefined. Can anyone please clarify this?

getmeToken function code is below

export const getmeToken = (userId, token) => {
    return fetch(` ${API}/payent/gettoken/${userId}`, {
        method: "GET",
        headers: {
            Accept: "application/json",
            "Content-Type": "application/json",
            Authorization: `Bearer ${token}`
        }
    }).then(response => {
        return response.json();
    })
    .catch(err => console.log(err))
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First, check the output of the getmeToken function. Then, you can use info?.error instead of info.error to handle this error.

Edit: Check the ${API}/payent/gettoken/${userId} url again. I think /payent/ is incorrect (/payment/ is correct)

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!