question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Response for getList SHOULD be an array and not an object or something else

See original GitHub issue

This code path was working earlier, recently noticed the following exception.

Not sure how to fix it from my end.

Object {data: Array[7], status: 200, headers: function, config: Object, originalElement: Object} rest-services.js:19 Error: Response for getList SHOULD be an array and not an object or something else at https://cdn.jsdelivr.net/restangular/latest/restangular.js:1059:31 at B (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js:94:5) at B (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js:94:5) at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js:95:173 at h.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js:103:456) at h.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js:101:218) at h.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js:104:264) at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js:68:23) at I (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js:72:109) at XMLHttpRequest.y.onreadystatechange (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js:73:154)

Additional info:

.config(function(RestangularProvider) {
    RestangularProvider.setBaseUrl('rest/index.php');
    RestangularProvider.setDefaultHttpFields({cache: true});
    RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
        var newResponse = response;
        if (angular.isArray(response)) {
            angular.forEach(newResponse, function(value, key) {
                newResponse[key].originalElement = angular.copy(value);
            });
        } else {
            newResponse.originalElement = angular.copy(response);
        }
        console.log(newResponse);
        return newResponse;
    });
})

Thanks

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
t00fcommented, Mar 5, 2014

Hello,

Apparently Restangular changed a few days ago and your backend cannot send objects anymore. You will have to parse it using addResponseInterceptor (what you did) to return a Javascript array.

Earlier, we were able to use setListTypeIsArray() method to accept Objects, but its seems it is now deprecated.

My backend should returns an Array of Objects with paginate information. These information are should be kept to display a paginate bar, and cannot be removed from the response. { ‘page_number’ : 1, ‘items_per_page’ : 10, ‘objects’: […] }

What would be the best way to solve this situation ? Would love to help Restangular but would like to have @mgonto advice first.

0reactions
CoolSuplexcommented, Jan 28, 2016

Question question: do getList() encodes the array? i.e. **Restangular.one(url).getList(‘sampleRefId’, array); because I am observing that in my code. So, we don’t have to use encodeURIComponent

Read more comments on GitHub >

github_iconTop Results From Across the Web

Response for getList SHOULD be an array and not an object ...
You're calling getList. which expects the data from the server to be an array (once it's been parsed into a real JS object)....
Read more >
Restangular Getlist() Does Not Return Array Of List Items
server that connects to an API using restangular but I keep getting the error Response for getList SHOULD be an array and not...
Read more >
Request and response objects - Django documentation
Quick overview¶. Django uses request and response objects to pass state through the system. When a page is requested, Django creates an HttpRequest...
Read more >
Indexed collections - JavaScript - MDN Web Docs - Mozilla
This chapter introduces collections of data which are ordered by an index value. This includes arrays and array-like constructs such as ...
Read more >
GraphQL List - How to use arrays in GraphQL schema ...
It is often common practice in REST APIs to return a JSON response with an array of objects. In GraphQL we would like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found