Angular promise resolved before factory execution
<p>We are trying to update a Factory which returns a promise. The original Factory uses $http->success->error and the controller has a .then(...).</p>

<p>We want to "migrate" from success/error to then/catch, but we get the following error message in the controller: <code>TypeError: Cannot read property 'then' of undefined</code>.</p>

<p>The Factory methods are the following ():</p>

<pre><code>'use strict';
xmsbsExtranet.factory('projectsTimeTrackingServices', ['$resource', '$http', '$log', '$q', 'membershipServices',
    function ($resource, $http, $log, $q, membershipServices) {
        var serviceBase = 'http://localhost:51617/api/';
        var _model = {};

        var service = {
            model: _model,
            getByProjectId: _getByProjectId_new,
            upsert: _upsert,
        };
        return service;

        function _getByProjectId_old(projectId) {
            var deferred = $q.defer();
            $http({
                method: "Get",
                url: "../api/projectsTimeTracking/project/" + projectId
            }).success(function (response) {
                deferred.resolve(response);
            }).error(function (err, status) {
                //membershipServices.logOut();
                deferred.reject(err);
            });

            return deferred.promise;
        };

        function _getByProjectId_new(projectId) {
            $http.get("../api/projectsTimeTracking/project/" + projectId)
            .then(function (response) {
                return response.data;
            }).catch(function (err, status) {
                //membershipServices.logOut();
                return err;
            });
        };

    }]);
</code></pre>

<p>The "short" version of the controller is as follows:</p>

<pre><code>projectsTimeTrackingServices
    .getByProjectId(vm.project.xrmId)
    .then(function (data) {
        //do something with the data
    });
</code></pre>

<p>When the service executes the method "_getByProjectId_old", everything Works as expected. But if I change it to "_getByProjectId_new", I get the afformentioned error.</p>

<p>Any Help will be greatly appreciated.
Best regards</p>