Error in resource configuration. Expected response to contain an object but got an array

helloworld picture helloworld · Jun 25, 2014 · Viewed 17.8k times · Source

I have an angular response that expects an array and the service call passes an array(can see it in network tab of chrome dev tools).

but I'm getting the following error in chrome console.

Error in resource configuration. Expected response to contain an object but got an array

here is my angular service:-

physicalServerModule.factory("physicalServerServices", ['$resource',
function ($resource) {

    var host = app.general.host;
    var port = app.general.port;

    var serverItemPath = 'v1/physicalserver/:x';
    var serverPath = 'v1/physicalserver/list';


    return {
        physicalServer: function () {
            return $resource(host + serverPath,{}, {
                query: {
                    method: 'GET',
                    isArray: true
                },
                create: {
                    method: 'POST'
                }
            });
        }
};
}]);

and I'm calling my service as below:-

var tileServiceCall = physicalServerServices.physicalServer();
tileServiceCall.get({},{}).$promise.then(function (response) {


 app.meta.physicalserver.tileItems = JSON.stringify(response);

}, function (error) {
alert("error");

});

my angularjs version is 1.2.15 can someone point me the root cause?

Answer

Ronald91 picture Ronald91 · Jun 25, 2014

Change tileServiceCall.get(..) to tileServiceCall.query(...).