Hello webix,
I use
webix.ajax().response(“blob”).post(api/lover
).then(r=>{//code})
it’s ok when server execute successful, but if server
throw new Error().
The Error only show on server, in browser console log
500 (Internal Server Error)
I dont know how to catch it on the client side and show it by webix.message
Love,
try to use catch
method
webix.ajax().response("blob")
.post('api/lover')
.then(r=>{/*code*/})
.catch(err => {
console.log(err);
});
it’s only show on the console that:
app.js:63 Uncaught DOMException: Failed to read the ‘responseText’ property from ‘XMLHttpRequest’: The value is only accessible if the object’s ‘responseType’ is ‘’ or ‘text’ (was ‘blob’).
Hello @duynq2197 ,
Unfortunately, I can’t repeat the described issue. Could you please provide more details?
As an alternative to the catch()
method, you could try using the onAjaxError
event:
webix.attachEvent("onAjaxError", function(xhr){
console.log(xhr);
if(xhr.status===500){
webix.message({type: 'error', text:"Please try again"});
}
});
hi.
onAjaxError can catch this error. And “Uncaught DOMException: Failed to read the ‘responseText’ property from ‘XMLHttpRequest’” notice came from that thing.
The case is :
In client
webix.ajax().response(“blob”).post(api/lover).then(r=>{//code})
In server:
i use ‘docxtemplater’ lib to create word file and res.end(out, ‘binary’)
thanks
Because blob is returned in the response (responseType = blob
). Additionally, you need to process this blob (so it still contains an error message).
To do this, you can use the built-in browser object of type FileReader
(it can read data from Blob (and from File, too)) and its API:
webix.attachEvent("onAjaxError", function(xhr){
const reader = new FileReader();
let response;
reader.onloadend = (e) => {
response = JSON.parse(reader.result);
console.log(response);
}
reader.readAsText(xhr.response); //read the data as a text string with the given encoding (utf-8 by default)
if(xhr.status===500){
webix.message({type: 'error', text:"Please try again"});
}
});
ok it’s really ok. I wish webix will improve to handle this . Thanks