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

224
Views
ReactJS: fetch give error cannot read properties

I'm trying to make an api call ( a get ) to download a document.

My problem is that when I make this api call I receive error:

TypeError: Cannot read properties of undefined (reading 'payload')

const printPin = event => {
    event.preventDefault()
    //....
    props.printedPin(scePersonaEntity.perCod, activateAlert)
}

my reducer:

export const printedPin= (id, callback) => {
  const requestUrl = `${apiUrl}/${id}/printpin`
  fetch(requestUrl)
    .then((response) => {
      response
        .blob()
        .then(blob => {
          console.log("blob ", blob)
          if (blob.type === 'application/problem+json') {
            callback();
          }
          else {
            const url = window.URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = 'pin.pdf';
            a.click();
          }
        })
        .catch(err => console.log(err))
    })
}

In your opinion how can I fix this error? Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think your .then chaining is incorrect.

Could you try this once?

 export const printedPin = (id, callback) => {
  const requestUrl = `${apiUrl}/${id}/printpin`
  fetch(requestUrl)
    .then((response) => response.blob()).then(blob => {
      console.log("blob ", blob)
      if (blob.type === 'application/problem+json') {
        callback();
      }
      else {
        const url = window.URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = url;
        a.download = 'pin.pdf';
        a.click();
      }
    })
    .catch(err => console.log(err))

}

Your first then will return response.blob() and next then will handle the response of the previous one.

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!