How to handle a resolved $promise with no data
<p>In my application, I have a form in which the user can add multiple records. When the page is loaded, I need to make a GET request to check the DB for existing records. If there are records that exist, I populate them on the page. No problem there. </p>

<p>The issue I'm having is when the DB has no existing records, the server return a 204 No Content. In the controller, the success function still gets executed but there is no data only the $promise object and $resolved: true. </p>

<p>Here is the code: </p>

<p>Factory:</p>

<pre><code>return $resource (
        https://my.backend/api/records/:id",
        {},
        {
            "getExistingRecords": {
                method: 'GET',
                isArray: false,
                params: {id: '@id'},
                withCredentials: true}
        }
    )
</code></pre>

<p>Controller:</p>

<pre><code>function initialize(id){
            alertFactory.getExistingRecords({id: id})
                .$promise
                .then(function (records){
                    if(records){
                        $scope.existingRecords = records;
                    }else {
                        $scope.existingRecords = {};
                    }
                },function(error){
                    Notification.error(error);
                });
        }
initialize(id);
</code></pre>

<p>When the server returns "204 No Content" I get this from the console</p>

<p><a href="http://i.stack.imgur.com/RaiyZ.png" rel="nofollow">Console Image</a></p>

<p>Is the only way to handle this to check for object properties of the records object?</p>

<p>For example: </p>

<pre><code>function initialize(id){
            alertFactory.getExistingRecords({id: id})
                .$promise
                .then(function (records){
                    if(records.recordName){
                        $scope.existingRecords = records;
                    }else {
                        $scope.existingRecords = {};
                    }
                },function(error){
                    Notification.error(error);
                });
        }
initialize(id);
</code></pre>

<p>Or am I missing something else?</p>