Error: Response for getList SHOULD be an array and not an object or something else
See original GitHub issueThis 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:
- Created 10 years ago
- Comments:8 (1 by maintainers)
Top GitHub Comments
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.
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