0

In order to consistently return a promise from my function, I either return the promise from an api call, or generate a deferred object, then reject it, and return it's promise...

function listIssues(user, repository, filters) {

    if (!user || !repository) {

        // this seems a bit long winded, is there an easier way..?
        var deferred = Q.defer();
        var warning = helper.chalk.gray('You must specifiy user/organization and repository name...');
        deferred.reject(warning);
        return deferred.promise;

    } else {

        return api.getIssues(user, repository, filters);

    }

}

Is there a shortcut to do all that in one step?

Billy Moon
  • 57,113
  • 24
  • 136
  • 237
  • 2
    [Sure there is](https://github.com/kriskowal/q/wiki/API-Reference#qrejectreason). – Bergi Feb 16 '16 at 00:04
  • Apart from the duplicate (the best I found for `Q`, `$q` would've been [easier](http://stackoverflow.com/q/33292312/1048572)), see also [here](http://stackoverflow.com/q/31933675/1048572). – Bergi Feb 16 '16 at 00:08

0 Answers0