[Q] Unhandled rejection reasons (should be empty

171 views
Skip to first unread message

a.su...@gmail.com

unread,
Nov 10, 2013, 1:13:01 AM11/10/13
to q-con...@googlegroups.com
Hi

Today I've started using q as a deferred/promises library and began reading some docs and writing a post with the following example

var xhr = new XMLHttpRequest();

function request(){
  var def = Q.defer();

  xhr.open('GET', 'data1.json');
  xhr.send();
  xhr.onreadystatechange = solver;

  function solver(){
    if (xhr.readyState === 4) {
      if(xhr.status === 200){
        def.resolve();
      }else{
        def.reject( new Error('Error message') );
      }
    }
  }

  return def.promise;
}

req = request();

req.then(function(){
  console.log('done!');
},function(err){
  console.log('fail!');
});


If the request is ok everything works as expected BUT if the request fails the console displays the following 

GET http://dev.home/demos/deferreds/data1.json 404 (Not Found) scripts.js:9
XHR finished loading: "http://dev.home/demos/deferreds/data1.json". scripts.js:9
[Q] Unhandled rejection reasons (should be empty): ["Error: Error message↵    at XMLHttpRequest.solver (http://dev.home/demos/deferreds/scripts.js:17:21)"] libs.js:989
fail!

Searching across the web, I found I can hide the [Q]'s messages putting something like
Q.stopUnhandledRejectionTracking();
at the top of file, but still do not figure out why is this message for.

How can I adapt my example to not show this message? or is totally normal this kind of message?

Nathan Stott

unread,
Nov 10, 2013, 9:26:38 PM11/10/13
to q-con...@googlegroups.com
Try chaining .done() onto the end of your .then like this:

req.then(function() { ... }, function() { ... }).done()


--
You received this message because you are subscribed to the Google Groups "Q Continuum (JavaScript)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to q-continuum...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Alfredo Sumaran

unread,
Nov 10, 2013, 9:55:32 PM11/10/13
to q-con...@googlegroups.com
On Sun, Nov 10, 2013 at 9:26 PM, Nathan Stott <nrs...@gmail.com> wrote:
Try chaining .done() onto the end of your .then like this:

req.then(function() { ... }, function() { ... }).done()


The same result. I ended up putting
Q.stopUnhandledRejectionTracking();
But I'd like to know what is the reason of this message.

Nathan Stott

unread,
Nov 10, 2013, 10:37:54 PM11/10/13
to q-con...@googlegroups.com
That should only happen when an error that is not handled by an attached rejection handler occurs iiuc.


--
Reply all
Reply to author
Forward
0 new messages