Как вернуть неудачное обещание?

Как я могу вернуть обещание, но сразу же вызову его блок отказов? Здесь грубый способ сделать это:

if (fail) {
    var q = $q.deferred();

    $timeout(function() {
        q.reject("")
    }, 1);

    return q.promise;
} else {
  return $http.get("/").then(function(data) {});
}

Ответ 1

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

Ref здесь:)

Ответ 2

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){})