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

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