Skip to content

Commit 7b88bbf

Browse files
committed
Merge pull request #220 from leeyeh/master
fix(query): throw error instead of return rejected Promise.
2 parents 5273682 + bfff771 commit 7b88bbf

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

lib/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ module.exports = function(AV) {
187187
if(!objectId) {
188188
var errorObject = new AV.Error(AV.Error.OBJECT_NOT_FOUND,
189189
"Object not found.");
190-
return AV.Promise.error(errorObject);
190+
throw errorObject;
191191
}
192192

193193
var self = this;

lib/user.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ module.exports = function(AV) {
251251
if (options && options.error) {
252252
options.error(this, error);
253253
}
254-
return AV.Promise.error(error);
254+
throw error;
255255
}
256256

257257
var password = (attrs && attrs.password) || this.get("password");
@@ -262,7 +262,7 @@ module.exports = function(AV) {
262262
if (options && options.error) {
263263
options.error(this, error);
264264
}
265-
return AV.Promise.error(error);
265+
throw error;
266266
}
267267

268268
return this.save(attrs, filterOutCallbacks(options)).then(function(model) {
@@ -304,7 +304,7 @@ module.exports = function(AV) {
304304
if (options && options.error) {
305305
options.error(this, error);
306306
}
307-
return AV.Promise.error(error);
307+
throw error;
308308
}
309309

310310
var smsCode = (attrs && attrs.smsCode) || this.get("smsCode");
@@ -316,7 +316,7 @@ module.exports = function(AV) {
316316
if (options && options.error) {
317317
options.error(this, error);
318318
}
319-
return AV.Promise.error(error);
319+
throw error;
320320
}
321321

322322
var newOptions = filterOutCallbacks(options);
@@ -737,9 +737,9 @@ module.exports = function(AV) {
737737
* logged in user using <code>current</code>.
738738
*
739739
* <p>Calls options.success or options.error on completion.</p>
740-
*
740+
*
741741
* @param {Object} data The response json data returned from third party token.
742-
* @param {string} platform Available platform for sign up.
742+
* @param {string} platform Available platform for sign up.
743743
* @param {Object} [callback] An object that has an optional success function, that takes no arguments and will be called on a successful puSH. and an error function that takes a AV.Error and will be called if the push failed.
744744
* @return {AV.Promise} A promise that is fulfilled with the user when
745745
* the login completes.

test/query.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ describe("Queries", function () {
2323

2424
});
2525

26+
it("should throw when get null", function () {
27+
28+
query = new AV.Query(GameScore);
29+
expect(function() {
30+
query.get(null, {
31+
success: function () {},
32+
error: function () {}
33+
});
34+
}).to.throwError();
35+
expect(function() {
36+
query.get(undefined, {
37+
success: function () {},
38+
error: function () {}
39+
});
40+
}).to.throwError();
41+
42+
});
43+
2644
});
2745

2846
describe("#cloudQuery", function () {

test/user.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ describe("User", function() {
2828

2929
});
3030

31-
31+
it("should throw when required field missing", function() {
32+
var user = new AV.User();
33+
user.set("username", username);
34+
expect(function() {
35+
user.signUp(null);
36+
}).to.throwError(/password/);
37+
var user = new AV.User();
38+
user.set("password", password);
39+
expect(function() {
40+
user.signUp(null);
41+
}).to.throwError(/name/);
42+
});
3243
});
3344

3445
describe("User.logIn and User.become", function() {
@@ -219,14 +230,14 @@ describe("User", function() {
219230

220231
describe("User logInAnonymously", function() {
221232
it("should create anonymous user, and login with AV.User.signUpOrlogInWithAuthData()", function(done) {
222-
var getFixedId = function () {
233+
var getFixedId = function () {
223234
var rawId = 13334230101333423010;
224-
var result = rawId.toString(16);
225-
return result;
235+
var result = rawId.toString(16);
236+
return result;
237+
}
238+
var data = {
239+
id: getFixedId()
226240
}
227-
var data = {
228-
id: getFixedId()
229-
}
230241

231242
AV.User.signUpOrlogInWithAuthData(data, "anonymous", {
232243
success: function(user) {

0 commit comments

Comments
 (0)