Skip to content

Commit a9621b4

Browse files
authored
Merge pull request #420 from leeyeh/chore-2.0
Chores
2 parents 6318e8b + 948f464 commit a9621b4

File tree

8 files changed

+41
-44
lines changed

8 files changed

+41
-44
lines changed

src/acl.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ module.exports = function(AV) {
2626
self.setWriteAccess(arg1, true);
2727
} else {
2828
if (_.isFunction(arg1)) {
29-
throw "AV.ACL() called with a function. Did you forget ()?";
29+
throw new Error('AV.ACL() called with a function. Did you forget ()?');
3030
}
3131
AV._objectEach(arg1, function(accessList, userId) {
3232
if (!_.isString(userId)) {
33-
throw "Tried to create an ACL with an invalid userId.";
33+
throw new Error('Tried to create an ACL with an invalid userId.');
3434
}
3535
self.permissionsById[userId] = {};
3636
AV._objectEach(accessList, function(allowed, permission) {
3737
if (permission !== "read" && permission !== "write") {
38-
throw "Tried to create an ACL with an invalid permission type.";
38+
throw new Error('Tried to create an ACL with an invalid permission type.');
3939
}
4040
if (!_.isBoolean(allowed)) {
41-
throw "Tried to create an ACL with an invalid permission value.";
41+
throw new Error('Tried to create an ACL with an invalid permission value.');
4242
}
4343
self.permissionsById[userId][permission] = allowed;
4444
});
@@ -62,10 +62,10 @@ module.exports = function(AV) {
6262
userId = "role:" + userId.getName();
6363
}
6464
if (!_.isString(userId)) {
65-
throw "userId must be a string.";
65+
throw new Error('userId must be a string.');
6666
}
6767
if (!_.isBoolean(allowed)) {
68-
throw "allowed must be either true or false.";
68+
throw new Error('allowed must be either true or false.');
6969
}
7070
var permissions = this.permissionsById[userId];
7171
if (!permissions) {
@@ -192,7 +192,7 @@ module.exports = function(AV) {
192192
if (_.isString(role)) {
193193
return this.getReadAccess("role:" + role);
194194
}
195-
throw "role must be a AV.Role or a String";
195+
throw new Error('role must be a AV.Role or a String');
196196
};
197197

198198
/**
@@ -212,7 +212,7 @@ module.exports = function(AV) {
212212
if (_.isString(role)) {
213213
return this.getWriteAccess("role:" + role);
214214
}
215-
throw "role must be a AV.Role or a String";
215+
throw new Error('role must be a AV.Role or a String');
216216
};
217217

218218
/**
@@ -232,7 +232,7 @@ module.exports = function(AV) {
232232
this.setReadAccess("role:" + role, allowed);
233233
return;
234234
}
235-
throw "role must be a AV.Role or a String";
235+
throw new Error('role must be a AV.Role or a String');
236236
};
237237

238238
/**
@@ -252,7 +252,7 @@ module.exports = function(AV) {
252252
this.setWriteAccess("role:" + role, allowed);
253253
return;
254254
}
255-
throw "role must be a AV.Role or a String";
255+
throw new Error('role must be a AV.Role or a String');
256256
};
257257

258258
};

src/cloudfunction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module.exports = function(AV) {
7474
data = { mobilePhoneNumber: data };
7575
}
7676
if(!data.mobilePhoneNumber) {
77-
throw "Missing mobilePhoneNumber.";
77+
throw new Error('Missing mobilePhoneNumber.');
7878
}
7979
var request = AVRequest("requestSmsCode", null, null, 'POST',
8080
data);
@@ -90,7 +90,7 @@ module.exports = function(AV) {
9090
*/
9191
verifySmsCode: function(code, phone){
9292
if(!code)
93-
throw "Missing sms code.";
93+
throw new Error('Missing sms code.');
9494
var params = {};
9595
if(_.isString(phone)) {
9696
params['mobilePhoneNumber'] = phone;

src/event.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ module.exports = function(AV) {
1616
* Triggering an event fires all callbacks in the order that `on` was
1717
* called.
1818
*
19-
* <p>For more information, see the
20-
* <a href="http://documentcloud.github.com/backbone/#Events">Backbone
21-
* documentation</a>.</p>
22-
*
19+
* @private
2320
* @example
2421
* var object = {};
2522
* _.extend(object, AV.Events);

src/object.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ module.exports = function(AV) {
159159
fetchWhenSave: function(enable){
160160
console.warn('AV.Object#fetchWhenSave is deprecated, use AV.Object#save with options.fetchWhenSave instead.');
161161
if (!_.isBoolean(enable)) {
162-
throw "Expect boolean value for fetchWhenSave";
162+
throw new Error('Expect boolean value for fetchWhenSave');
163163
}
164164
this._fetchWhenSave = enable;
165165
},
@@ -1288,7 +1288,7 @@ module.exports = function(AV) {
12881288
*/
12891289
AV.Object._getSubclass = function(className) {
12901290
if (!_.isString(className)) {
1291-
throw "AV.Object._getSubclass requires a string argument.";
1291+
throw new Error('AV.Object._getSubclass requires a string argument.');
12921292
}
12931293
var ObjectClass = AV.Object._classMap[className];
12941294
if (!ObjectClass) {

src/op.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ module.exports = function(AV) {
178178
} else if (previous instanceof AV.Op.Increment) {
179179
return new AV.Op.Increment(this.amount() + previous.amount());
180180
} else {
181-
throw "Op is invalid after previous op.";
181+
throw new Error('Op is invalid after previous op.');
182182
}
183183
},
184184

@@ -231,7 +231,7 @@ module.exports = function(AV) {
231231
} else if (previous instanceof AV.Op.Add) {
232232
return new AV.Op.Add(previous.objects().concat(this.objects()));
233233
} else {
234-
throw "Op is invalid after previous op.";
234+
throw new Error('Op is invalid after previous op.');
235235
}
236236
},
237237

@@ -288,7 +288,7 @@ module.exports = function(AV) {
288288
} else if (previous instanceof AV.Op.AddUnique) {
289289
return new AV.Op.AddUnique(this._estimate(previous.objects()));
290290
} else {
291-
throw "Op is invalid after previous op.";
291+
throw new Error('Op is invalid after previous op.');
292292
}
293293
},
294294

@@ -361,7 +361,7 @@ module.exports = function(AV) {
361361
} else if (previous instanceof AV.Op.Remove) {
362362
return new AV.Op.Remove(_.union(previous.objects(), this.objects()));
363363
} else {
364-
throw "Op is invalid after previous op.";
364+
throw new Error('Op is invalid after previous op.');
365365
}
366366
},
367367

@@ -405,14 +405,14 @@ module.exports = function(AV) {
405405
var pointerToId = function(object) {
406406
if (object instanceof AV.Object) {
407407
if (!object.id) {
408-
throw "You can't add an unsaved AV.Object to a relation.";
408+
throw new Error('You can\'t add an unsaved AV.Object to a relation.');
409409
}
410410
if (!self._targetClassName) {
411411
self._targetClassName = object.className;
412412
}
413413
if (self._targetClassName !== object.className) {
414-
throw "Tried to create a AV.Relation with 2 different types: " +
415-
self._targetClassName + " and " + object.className + ".";
414+
throw new Error("Tried to create a AV.Relation with 2 different types: " +
415+
self._targetClassName + " and " + object.className + ".");
416416
}
417417
return object.id;
418418
}
@@ -486,12 +486,12 @@ module.exports = function(AV) {
486486
if (!previous) {
487487
return this;
488488
} else if (previous instanceof AV.Op.Unset) {
489-
throw "You can't modify a relation after deleting it.";
489+
throw new Error('You can\'t modify a relation after deleting it.');
490490
} else if (previous instanceof AV.Op.Relation) {
491491
if (previous._targetClassName &&
492492
previous._targetClassName !== this._targetClassName) {
493-
throw "Related object must be of class " + previous._targetClassName +
494-
", but " + this._targetClassName + " was passed in.";
493+
throw new Error("Related object must be of class " + previous._targetClassName +
494+
", but " + this._targetClassName + " was passed in.");
495495
}
496496
var newAdd = _.union(_.difference(previous.relationsToAdd,
497497
this.relationsToRemove),
@@ -504,7 +504,7 @@ module.exports = function(AV) {
504504
newRelation._targetClassName = this._targetClassName;
505505
return newRelation;
506506
} else {
507-
throw "Op is invalid after previous op.";
507+
throw new Error('Op is invalid after previous op.');
508508
}
509509
},
510510

@@ -516,16 +516,16 @@ module.exports = function(AV) {
516516
if (this._targetClassName) {
517517
if (oldValue.targetClassName) {
518518
if (oldValue.targetClassName !== this._targetClassName) {
519-
throw "Related object must be a " + oldValue.targetClassName +
520-
", but a " + this._targetClassName + " was passed in.";
519+
throw new Error("Related object must be a " + oldValue.targetClassName +
520+
", but a " + this._targetClassName + " was passed in.");
521521
}
522522
} else {
523523
oldValue.targetClassName = this._targetClassName;
524524
}
525525
}
526526
return oldValue;
527527
} else {
528-
throw "Op is invalid after previous op.";
528+
throw new Error('Op is invalid after previous op.');
529529
}
530530
}
531531
});

src/query.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module.exports = function(AV) {
9090
}
9191

9292
if (className !== q.className) {
93-
throw "All queries must be for the same class";
93+
throw new Error('All queries must be for the same class');
9494
}
9595
});
9696
var query = new AV.Query(className);
@@ -117,7 +117,7 @@ module.exports = function(AV) {
117117
}
118118

119119
if (className !== q.className) {
120-
throw "All queries must be for the same class";
120+
throw new Error('All queries must be for the same class');
121121
}
122122
});
123123
var query = new AV.Query(className);

src/search.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,15 @@ module.exports = function(AV) {
259259
params.sid = this._sid;
260260
}
261261
if(!this._queryString) {
262-
throw 'Please set query string.';
262+
throw new Error('Please set query string.');
263263
} else {
264264
params.q = this._queryString;
265265
}
266266
if(this._highlights) {
267267
params.highlights = this._highlights.join(',');
268268
}
269269
if(this._sortBuilder && params.order) {
270-
throw 'sort and order can not be set at same time.';
270+
throw new Error('sort and order can not be set at same time.');
271271
}
272272
if(this._sortBuilder) {
273273
params.sort = this._sortBuilder.build();

src/user.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,14 @@ module.exports = function(AV) {
381381
*/
382382
follow: function(target, options){
383383
if(!this.id){
384-
throw "Please signin.";
384+
throw new Error('Please signin.');
385385
}
386386
if(!target){
387-
throw "Invalid target user.";
387+
throw new Error('Invalid target user.');
388388
}
389389
var userObjectId = _.isString(target) ? target: target.id;
390390
if(!userObjectId){
391-
throw "Invalid target user.";
391+
throw new Error('Invalid target user.');
392392
}
393393
var route = 'users/' + this.id + '/friendship/' + userObjectId;
394394
var request = AVRequest(route, null, null, 'POST', null, options);
@@ -403,14 +403,14 @@ module.exports = function(AV) {
403403
*/
404404
unfollow: function(target, options){
405405
if(!this.id){
406-
throw "Please signin.";
406+
throw new Error('Please signin.');
407407
}
408408
if(!target){
409-
throw "Invalid target user.";
409+
throw new Error('Invalid target user.');
410410
}
411411
var userObjectId = _.isString(target) ? target: target.id;
412412
if(!userObjectId){
413-
throw "Invalid target user.";
413+
throw new Error('Invalid target user.');
414414
}
415415
var route = 'users/' + this.id + '/friendship/' + userObjectId;
416416
var request = AVRequest(route, null, null, 'DELETE', null, options);
@@ -824,7 +824,7 @@ module.exports = function(AV) {
824824
*/
825825
followerQuery: function(userObjectId) {
826826
if(!userObjectId || !_.isString(userObjectId)) {
827-
throw "Invalid user object id.";
827+
throw new Error('Invalid user object id.');
828828
}
829829
var query = new AV.FriendShipQuery('_Follower');
830830
query._friendshipTag ='follower';
@@ -840,7 +840,7 @@ module.exports = function(AV) {
840840
*/
841841
followeeQuery: function(userObjectId) {
842842
if(!userObjectId || !_.isString(userObjectId)) {
843-
throw "Invalid user object id.";
843+
throw new Error('Invalid user object id.');
844844
}
845845
var query = new AV.FriendShipQuery('_Followee');
846846
query._friendshipTag ='followee';

0 commit comments

Comments
 (0)