After some reading and experimentation, I came up with something that shows promise, but doesn't quite work. A bit of background: the function shown below is the "onerror" handler for the XMLHttpRequest object. Its sole argument is the "target" of the error (the XMLHttpRequest), from which I obtain an nsIRequest interface that contains a status field.
Here's the code:
req.onerror =
function (e)
{
var req =
e.target.channel.QueryInterface(Components.interfaces.nsIRequest); var sbServ = Components.classes["@mozilla.org/intl/stringbundle;1"].
getService(Components.interfaces.nsIStringBundleService); var errorText =
sbServ.formatStatusMessage(req.status, // sample value: 2152398861
// means "connection refused"
"This is a message"
);
alert(errorText);
}req.status contain values that seem valid: they vary based on the error condition encountered--"connection refused", "no route to host", etc. But the formatStatusMessage() method always throws this exception:
Error: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIStringBundleService.formatStatusMessage]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: file:///Users/chuck/errtest.html :: anonymous :: line 34" data: no]
Source File: file:///Users/chuck/errtest.html
Line: 34
Am I:
1.) Handing it a "status" (first argument) that is invalid or needs to be massaged in some way? I also tried guessing a few values (positive and negative) and hardcoding them into the first argument, but I got the same result.
2.) Handing it an inappropriate statusArg (second argument)? I'm assuming it can just be text. I tried a blank string, which got me the same exception, and I tried the "null" value, which crashed the browser. I'll file that as a bug.
3.) Barking up the wrong tree entirely? I thought the nsIStringBundleService looked like a good fit, but maybe I've misunderstood its purpose or usage.
Thanks,
Chuck _______________________________________________ Mozilla-xpcom mailing list [EMAIL PROTECTED] http://mail.mozilla.org/listinfo/mozilla-xpcom
