Skip to content

Instantly share code, notes, and snippets.

@yassermzh
Last active August 29, 2015 14:10
Show Gist options
  • Save yassermzh/5457771714a775e1c65b to your computer and use it in GitHub Desktop.
Save yassermzh/5457771714a775e1c65b to your computer and use it in GitHub Desktop.
Q promises

done()

When the error handler in fail throw some errors, it woull be sillently dismissed and there is no way of knowing what's wrong.

var Q = require('q');
function asyncTask() {
    return Q.reject();
}

function errorHandler() {
    // calling log of undefined logger, throws error
    logger.log();
}

asyncTask()
.fail(function() {
    errorHandler();
})

To fix it, we should call .done() at the end of promise chain, so if there are any errors not catched yet, they would be thrown.

asyncTask()
.fail(function() {
    errorHandler();
})
.done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment