An SDK request will always invoke onComplete when the request is considered complete for the network. This means that onComplete is invoked anyway, ignoring if the request returned an error or success.
To find out what your error is, you need to check the Response object (the object passed to the onComplete function) the "status" property ( response.status ). It contains the status code for the request. To view status codes, view the list on the mozilla dev network . If the response status is 0, the request has completed completely and the user is probably disconnected, or the goal cannot be reached.
The timeout will be either a status code 504 or 0. The implementation will be similar to the implementation:
var Request = require("sdk/request"); Request({ url: "http://foo.bar/request.target", onComplete: function(response) { if(response.status==0||response.status==504) {
I personally use the check function on the request object, which returns me a number, which depends on whether I have the correct answer, an error from the web server or a connection problem (status codes 4xx and 0).
source share