Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda