Should the xmlhttprequest error message have an error message?

I am working on creating an AJAX request from a Firefox extension. I have this code:

function GetMenu(){ var oReq = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); // Setup event handlers - must be set before calling open() oReq.addEventListener("progress", updateProgress, false); oReq.addEventListener("load", transferComplete, false); oReq.addEventListener("error", transferFailed, false); oReq.addEventListener("abort", transferCanceled, false); oReq.open('POST', "http://www.foo.bar/", true); oReq.send('your=data&and=more&stuff=here'); } function transferFailed(evt) { Application.console.log("An error occurred while transferring the file."); Application.console.log(this.responseText); for(var i in evt) Application.console.log(i+ ' => '+evt[i]); } 

The request fails because http://www.foo.bar/ does not exist (I suppose). My question is: why is there no error message in the evt object passed to transferFailed () that says: “Domain does not exist” or “DNS error” or something like that? None of the properties of the event object have any signs that the problem is, there is no message, error code, etc.

Should there be some indication of what the actual error is?

+6
source share
2 answers

Since you are using chrome privileges:

 function transferFailed(evt) { if (this.channel && this.channel.status == Components.results.NS_ERROR_UNKNOWN_HOST) { alert("DNS error"); } } 

(what @paa said in the comment).

See (you may need QueryInterface / instanceof ):

+1
source

Network errors are not reported to the caller.

status (and statusText , although it is whatever the server likes) concerns HTTP.

+1
source

Source: https://habr.com/ru/post/953154/


All Articles