aboutsummaryrefslogtreecommitdiffstats
path: root/src/ngResource/resource.js
diff options
context:
space:
mode:
authorPete Bacon Darwin2013-07-30 22:48:56 +0100
committerPete Bacon Darwin2013-07-31 21:17:37 +0100
commita644ca7b4e6ba84a467bcabed8f99386eda7fb14 (patch)
tree7dced3f293759bf4c9e8127b606852aaf118cc9a /src/ngResource/resource.js
parent24a4450f2b4bcc5b616fae34b6815252896d1756 (diff)
downloadangular.js-a644ca7b4e6ba84a467bcabed8f99386eda7fb14.tar.bz2
fix(resource): check whether response matches action.isArray
When using $resource you must setup your actions carefully based on what the server returns. If the server responds to a request with an array then you must configure the action with `isArray:true` and vice versa. The built-in `get` action defaults to `isArray:false` and the `query` action defaults to `isArray:true`, which is must be changed if the server does not do this. Before the error message was an exception inside angular.copy, which didn't explain what the real problem was. Rather than changing the way that angular.copy works, this change ensures that a better error message is provided to the programmer if they do not set up their resource actions correctly. Closes #2255, #1044
Diffstat (limited to 'src/ngResource/resource.js')
-rw-r--r--src/ngResource/resource.js5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js
index 92cbcd16..003b41f1 100644
--- a/src/ngResource/resource.js
+++ b/src/ngResource/resource.js
@@ -473,6 +473,11 @@ angular.module('ngResource', ['ng']).
promise = value.$promise;
if (data) {
+ if ( angular.isArray(data) != !!action.isArray ) {
+ throw ngResourceMinErr('badcfg', 'Error in resource configuration. Expected response' +
+ ' to contain an {0} but got an {1}',
+ action.isArray?'array':'object', angular.isArray(data)?'array':'object');
+ }
if (action.isArray) {
value.length = 0;
forEach(data, function(item) {