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

221
Views
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
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!