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

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

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 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