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

214
Visualizações
How to receive errors while downloading a file using axios

My code:

rest client:

return axios.get(url, {
    responseType: 'arraybuffer'
});

handling response:

  const link = document.createElement('a');
            link.href = window.URL.createObjectURL(new Blob([response.data]));
            link.target = "_blank"; 
            link.click();

works nicely if there are no errors on the server side. However, when there is an error in the server API, I get no details of it, because of the response type being arraybuffer.

    .catch((error) => {
        dispatch(showError("An Error Occured", error)); //error does not contain the expected details
    });

I tried not setting the arraybuffer type, instead using the TextDecoder, however the result pdf seems to be corrupt (empty display).

How can I modify the existing setup in order to be able to receive details in case an error occurs?

Edit: Solution: OK, I got it, I can decode the error information from the error.data:

var data:any = JSON.parse(new TextDecoder().decode(error.data));

and then use the error code & message.

about 4 years ago · Juan Pablo Isaza
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