How to return a failed promise? How to return a failed promise? angularjs angularjs

How to return a failed promise?


if( fail ) {    return $q.reject(yourReasonObject);}else ...

Ref here :)


function setLike(productId){    return new Promise(function(succeed, fail) {        if(!productId) throw new Error();        jQuery.ajax({            success: function (res) {                succeed(res)            }        })    })}    setLike(id).then(function(){       //render    }).catch(function(e){})