Skip to content

Commit 17cdf07

Browse files
committed
Fixes #69
1 parent 4099670 commit 17cdf07

File tree

13 files changed

+46
-17
lines changed

13 files changed

+46
-17
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
##### 0.9.1 - xx May 2014
2+
3+
###### Backwards compatible bug fixes
4+
- #69 - Failed requests should throw an error, not just return it
5+
16
##### 0.9.0 - 22 May 2014
27

38
###### Breaking API changes

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
__Data store for Angular.js.__
44

5-
__Latest Release:__ [0.8.1](http://angular-data.codetrain.io/)
6-
__master:__ [0.9.0](http://angular-data-next.codetrain.io/)
5+
__Latest Release:__ [0.9.1](http://angular-data.codetrain.io/)
6+
__master:__ [0.9.1](http://angular-data-next.codetrain.io/)
77

88
Angular-data is in a pre-1.0.0 development stage; the API is fluctuating, not a lot of tests yet, etc.
99

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Jason Dobry",
33
"name": "angular-data",
44
"description": "Data store for Angular.js.",
5-
"version": "0.9.0",
5+
"version": "0.9.1",
66
"homepage": "http://angular-data.codetrain.io/",
77
"repository": {
88
"type": "git",

dist/angular-data.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,7 @@ function find(resourceName, id, options) {
21822182
}
21832183
}, function (err) {
21842184
delete resource.pendingQueries[id];
2185-
return err;
2185+
return _this.$q.reject(err);
21862186
});
21872187
}
21882188

@@ -2243,14 +2243,14 @@ function _findAll(utils, resourceName, params, options) {
22432243
try {
22442244
return processResults.apply(_this, [utils, data, resourceName, queryHash]);
22452245
} catch (err) {
2246-
throw new _this.errors.UnhandledError(err);
2246+
return _this.$q.reject(_this.errors.UnhandledError(err));
22472247
}
22482248
} else {
22492249
return data;
22502250
}
22512251
}, function (err) {
22522252
delete resource.pendingQueries[queryHash];
2253-
return err;
2253+
return _this.$q.reject(err);
22542254
});
22552255
}
22562256

@@ -4220,13 +4220,14 @@ function get(resourceName, id, options) {
42204220
} else if (!this.utils.isObject(options)) {
42214221
throw new this.errors.IllegalArgumentError(errorPrefix + 'options: Must be an object!', { options: { actual: typeof options, expected: 'object' } });
42224222
}
4223+
var _this = this;
42234224

42244225
try {
42254226
// cache miss, request resource from server
42264227
var item = this.store[resourceName].index.get(id);
42274228
if (!item && options.loadFromServer) {
42284229
this.find(resourceName, id).then(null, function (err) {
4229-
throw err;
4230+
return _this.$q.reject(err);
42304231
});
42314232
}
42324233

@@ -4963,7 +4964,7 @@ module.exports = [function () {
49634964
* @id angular-data
49644965
* @name angular-data
49654966
* @description
4966-
* __Version:__ 0.9.0
4967+
* __Version:__ 0.9.1
49674968
*
49684969
* ## Install
49694970
*

dist/angular-data.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

guide/nav.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<i class="icon-wrench icon-white"></i> API <b class="caret"></b>
7373
</a>
7474
<ul class="dropdown-menu">
75-
<li class="nav-header">Angular-data - 0.9.0</li>
75+
<li class="nav-header">Angular-data - 0.9.1</li>
7676
<li>
7777
<a href="/documentation/api/angular-data/angular-data">Overview</a>
7878
</li>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-data",
33
"description": "Data store for Angular.js.",
4-
"version": "0.9.0",
4+
"version": "0.9.1",
55
"homepage": "http://angular-data.codetrain.io",
66
"repository": {
77
"type": "git",

src/datastore/async_methods/find.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function find(resourceName, id, options) {
8686
}
8787
}, function (err) {
8888
delete resource.pendingQueries[id];
89-
return err;
89+
return _this.$q.reject(err);
9090
});
9191
}
9292

src/datastore/async_methods/findAll.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ function _findAll(utils, resourceName, params, options) {
4040
try {
4141
return processResults.apply(_this, [utils, data, resourceName, queryHash]);
4242
} catch (err) {
43-
throw new _this.errors.UnhandledError(err);
43+
return _this.$q.reject(_this.errors.UnhandledError(err));
4444
}
4545
} else {
4646
return data;
4747
}
4848
}, function (err) {
4949
delete resource.pendingQueries[queryHash];
50-
return err;
50+
return _this.$q.reject(err);
5151
});
5252
}
5353

src/datastore/sync_methods/get.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ function get(resourceName, id, options) {
4141
} else if (!this.utils.isObject(options)) {
4242
throw new this.errors.IllegalArgumentError(errorPrefix + 'options: Must be an object!', { options: { actual: typeof options, expected: 'object' } });
4343
}
44+
var _this = this;
4445

4546
try {
4647
// cache miss, request resource from server
4748
var item = this.store[resourceName].index.get(id);
4849
if (!item && options.loadFromServer) {
4950
this.find(resourceName, id).then(null, function (err) {
50-
throw err;
51+
return _this.$q.reject(err);
5152
});
5253
}
5354

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @id angular-data
77
* @name angular-data
88
* @description
9-
* __Version:__ 0.9.0
9+
* __Version:__ 0.9.1
1010
*
1111
* ## Install
1212
*

test/integration/datastore/async_methods/find.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,15 @@ describe('DS.find(resourceName, id[, options]): ', function () {
100100
assert.equal(lifecycle.serialize.callCount, 0, 'serialize should have been called');
101101
assert.equal(lifecycle.deserialize.callCount, 1, 'deserialize should have been called');
102102
});
103+
it('should correctly propagate errors', function () {
104+
$httpBackend.expectGET('http://test.angular-cache.com/posts/5').respond(404, 'Not Found');
105+
106+
DS.find('post', 5).then(function () {
107+
fail('Should not have succeeded!');
108+
}, function (err) {
109+
assert.equal(err.data, 'Not Found');
110+
});
111+
112+
$httpBackend.flush();
113+
});
103114
});

test/integration/datastore/async_methods/findAll.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,15 @@ describe('DS.findAll(resourceName, params[, options]): ', function () {
101101
assert.equal(lifecycle.serialize.callCount, 0, 'serialize should have been called');
102102
assert.equal(lifecycle.deserialize.callCount, 1, 'deserialize should have been called');
103103
});
104+
it('should correctly propagate errors', function () {
105+
$httpBackend.expectGET(/http:\/\/test\.angular-cache\.com\/posts\??/).respond(404, 'Not Found');
106+
107+
DS.findAll('post', {}).then(function () {
108+
fail('Should not have succeeded!');
109+
}, function (err) {
110+
assert.equal(err.data, 'Not Found');
111+
});
112+
113+
$httpBackend.flush();
114+
});
104115
});

0 commit comments

Comments
 (0)