Skip to content

Commit c97c90b

Browse files
committed
add error handle
1 parent cda690d commit c97c90b

1 file changed

Lines changed: 54 additions & 8 deletions

File tree

auth.js

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ kidstuff.auth.module.provider('auth',function() {
3535
}
3636

3737
auth.login = function(email, password, success, error) {
38+
if(typeof email != 'string' || typeof password != 'string') {
39+
return error({error:'email/password must be string'})
40+
}
41+
3842
$http({
3943
method: 'POST',
4044
url: config.endPoint+'/tokens',
@@ -63,8 +67,9 @@ kidstuff.auth.module.provider('auth',function() {
6367

6468
auth.getUser = function(id, success, error) {
6569
if(typeof id != 'string') {
66-
return;
70+
return error({error:'id must be string'});
6771
}
72+
6873
$http({
6974
method: 'GET',
7075
url: config.endPoint+'/users/'+id,
@@ -84,7 +89,7 @@ kidstuff.auth.module.provider('auth',function() {
8489

8590
auth.createUser = function(userInfo, success, error) {
8691
if(typeof userInfo != 'object') {
87-
return;
92+
return error({error:'userInfo must be object'});
8893
}
8994

9095
$http({
@@ -107,7 +112,7 @@ kidstuff.auth.module.provider('auth',function() {
107112

108113
auth.removeUser = function(userId, success, error) {
109114
if(typeof userId != 'string') {
110-
return;
115+
return error({error:'userId must be string'});
111116
}
112117

113118
$http({
@@ -128,9 +133,14 @@ kidstuff.auth.module.provider('auth',function() {
128133
}
129134

130135
auth.updateUserProfile = function(id, profile, success, error) {
136+
if(typeof id != 'string') {
137+
return error({error:'id must be string'});
138+
}
139+
131140
if(typeof profile != 'object') {
132-
return;
141+
return error({error:'profile must be object'})
133142
}
143+
134144
$http({
135145
method: 'PATCH',
136146
url: config.endPoint+'/users/'+id+'/profile',
@@ -150,8 +160,12 @@ kidstuff.auth.module.provider('auth',function() {
150160
}
151161

152162
auth.updateUserApproval = function(id, approve, success, error) {
163+
if(typeof id != 'string') {
164+
return error({error:'id must be string'});
165+
}
166+
153167
if(typeof approve != 'boolean') {
154-
return;
168+
return error({error:'approve must be boolean'});
155169
}
156170

157171
$http({
@@ -175,6 +189,10 @@ kidstuff.auth.module.provider('auth',function() {
175189
}
176190

177191
auth.listUser = function(params, success, error) {
192+
if(typeof params != 'object') {
193+
return error({error:'params must be object'})
194+
}
195+
178196
$http({
179197
method: 'GET',
180198
url: config.endPoint+'/users',
@@ -195,7 +213,7 @@ kidstuff.auth.module.provider('auth',function() {
195213

196214
auth.removeUserGroup = function(userId, groupId, success, error) {
197215
if(typeof userId != 'string' || typeof groupId != 'string') {
198-
return;
216+
return error({error:'userId/groupId must be string'});
199217
}
200218

201219
$http({
@@ -217,7 +235,7 @@ kidstuff.auth.module.provider('auth',function() {
217235

218236
auth.addUserGroup = function(userId, groupId, success, error) {
219237
if(typeof userId != 'string' || typeof groupId != 'string') {
220-
return;
238+
return error({error:'userId/groupId must be string'});
221239
}
222240

223241
$http({
@@ -241,6 +259,10 @@ kidstuff.auth.module.provider('auth',function() {
241259
}
242260

243261
auth.listGroup = function(params, success, error) {
262+
if(typeof params != 'object') {
263+
return error({error:'params must be object'})
264+
}
265+
244266
$http({
245267
method: 'GET',
246268
url: config.endPoint+'/groups',
@@ -260,6 +282,10 @@ kidstuff.auth.module.provider('auth',function() {
260282
}
261283

262284
auth.createGroup = function(group, success, error) {
285+
if(typeof group != 'object') {
286+
return error({error:'group must be object'})
287+
}
288+
263289
$http({
264290
method: 'POST',
265291
url: config.endPoint+'/groups',
@@ -279,6 +305,10 @@ kidstuff.auth.module.provider('auth',function() {
279305
}
280306

281307
auth.getGroup = function(id, success, error) {
308+
if(typeof id != 'string') {
309+
return error({error:'id must be string'});
310+
}
311+
282312
$http({
283313
method: 'GET',
284314
url: config.endPoint+'/groups/'+id,
@@ -297,6 +327,10 @@ kidstuff.auth.module.provider('auth',function() {
297327
}
298328

299329
auth.updateGroup = function(group, success, error) {
330+
if(typeof group != 'object') {
331+
return error({error:'group must be object'})
332+
}
333+
300334
$http({
301335
method: 'PATCH',
302336
url: config.endPoint+'/groups/'+group.Id,
@@ -316,6 +350,10 @@ kidstuff.auth.module.provider('auth',function() {
316350
}
317351

318352
auth.removeGroup = function(id, success, error) {
353+
if(typeof id != 'string') {
354+
return error({error:'id must be string'});
355+
}
356+
319357
$http({
320358
method: 'DELETE',
321359
url: config.endPoint+'/groups/'+id,
@@ -336,7 +374,7 @@ kidstuff.auth.module.provider('auth',function() {
336374

337375
auth.updateSettings = function(settings, success, error) {
338376
if(typeof settings != "object") {
339-
return
377+
return error({error:'settings must be object'})
340378
}
341379

342380
$http({
@@ -358,6 +396,10 @@ kidstuff.auth.module.provider('auth',function() {
358396
}
359397

360398
auth.getSettings = function(keys, success, error) {
399+
if(keys.constructor != Array) {
400+
return error({error: 'keys must be array of string'});
401+
}
402+
361403
$http({
362404
method: 'GET',
363405
url: config.endPoint+'/settings?keys='+keys.toString(),
@@ -376,6 +418,10 @@ kidstuff.auth.module.provider('auth',function() {
376418
}
377419

378420
auth.removeSettings = function(keys, success, error) {
421+
if(keys.constructor != Array) {
422+
return error({error: 'keys must be array of string'});
423+
}
424+
379425
$http({
380426
method: 'DELETE',
381427
url: config.endPoint+'/settings?keys='+keys.toString(),

0 commit comments

Comments
 (0)