Failed to process file download, how to convert Blob object to Json?

[ description ]:
axios sets the error that responseType:blob, expects to report to the backend when downloading fails.
but at this time, the error message returned by the backend has been converted to blob object. How to transfer the blob object back to the original Json?

or how to handle interception, because the axios interceptor cannot tell whether to enter then or catch when blob object.
when the backend returns an error status code other than 200, it does not return Json object parsing

[ related codes ]

  https://codeshelper.com/q/10.


use FileReader

var reader = new FileReader()
reader.onload = e => console.log(JSON.parse(e.target.result))
reader.readAsText(blob)

//blobtypejsonstreamstreamnamejsonnamefileReaderblob

var reader = new FileReader();
reader.addEventListener("loadend", function() {
    console.log(JSON.parse(reader.result));
});
reader.readAsText(blob,['utf-8']);

  

the first and second floors are correct, but I must add that if (res.data.type = 'application/json') {. }, before it can be executed. I would like to remind you all here

Menu