Skip to content

Commit dbfd19e

Browse files
committed
Replace exceptions in PFUser.signUp with errors.
1 parent ff178c4 commit dbfd19e

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

Parse/Internal/User/PFUserPrivate.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ extern NSString *const PFUserCurrentUserKeychainItemName;
3131

3232
- (void)synchronizeAllAuthData;
3333

34-
- (void)checkSignUpParams;
35-
3634
- (BFTask *)_handleServiceLoginCommandResult:(PFCommandResult *)result;
3735

3836
- (void)synchronizeAuthDataWithAuthType:(NSString *)authType;

Parse/PFUser.m

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,26 @@ - (void)_checkSaveParametersWithCurrentUser:(PFUser *)currentUser {
121121
}
122122

123123
// Checks the properties on the object before signUp.
124-
- (void)checkSignUpParams {
125-
@synchronized ([self lock]) {
126-
PFConsistencyAssert(self.username, @"Cannot sign up without a username.");
127-
PFConsistencyAssert(self.password, @"Cannot sign up without a password.");
128-
129-
PFConsistencyAssert([self isDirty:NO] && !self.objectId, @"Cannot sign up an existing user.");
130-
}
124+
- (BFTask *)_validateSignUpAsync {
125+
return [BFTask taskFromExecutor:[BFExecutor defaultExecutor] withBlock:^id{
126+
NSError *error = nil;
127+
@synchronized (self.lock) {
128+
if (!self.username) {
129+
error = [PFErrorUtilities errorWithCode:kPFErrorUsernameMissing
130+
message:@"Cannot sign up without a username."];
131+
} else if (!self.password) {
132+
error = [PFErrorUtilities errorWithCode:kPFErrorUserPasswordMissing
133+
message:@"Cannot sign up without a password."];
134+
} else if (![self isDirty:NO] || self.objectId) {
135+
error = [PFErrorUtilities errorWithCode:kPFErrorUsernameTaken
136+
message:@"Cannot sign up an existing user."];
137+
}
138+
}
139+
if (error) {
140+
return [BFTask taskWithError:error];
141+
}
142+
return nil;
143+
}];
131144
}
132145

133146
- (NSMutableDictionary *)_convertToDictionaryForSaving:(PFOperationSet *)changes
@@ -444,20 +457,19 @@ - (BFTask *)signUpAsync:(BFTask *)toAwait {
444457

445458
// Otherwise, return an error
446459
NSError *error = [PFErrorUtilities errorWithCode:kPFErrorUsernameTaken
447-
message:@"Cannot sign up a user that has already signed up."];
460+
message:@"Cannot sign up a user that has already signed up."];
448461
return [BFTask taskWithError:error];
449462
}
450463

451464
// If the operationSetQueue is has operation sets in it, then a save or signUp is in progress.
452465
// If there is a signUp or save already in progress, don't allow another one to start.
453466
if ([self _hasOutstandingOperations]) {
454467
NSError *error = [PFErrorUtilities errorWithCode:kPFErrorUsernameTaken
455-
message:@"Cannot sign up a user that is already signing up."];
468+
message:@"Cannot sign up a user that is already signing up."];
456469
return [BFTask taskWithError:error];
457470
}
458471

459-
return [BFTask taskFromExecutor:[BFExecutor immediateExecutor] withBlock:^id{
460-
[self checkSignUpParams];
472+
return [[self _validateSignUpAsync] continueWithSuccessBlock:^id(BFTask *task) {
461473
if (currentUser && [PFAnonymousUtils isLinkedWithUser:currentUser]) {
462474
// self doesn't have any outstanding saves, so we can safely merge its operations
463475
// into the current user.
@@ -1160,7 +1172,6 @@ - (void)signUpInBackgroundWithBlock:(PFBooleanResultBlock)block {
11601172
return;
11611173
}
11621174
}
1163-
[self checkSignUpParams];
11641175
[[self signUpInBackground] thenCallBackOnMainThreadWithBoolValueAsync:block];
11651176
}
11661177
}

0 commit comments

Comments
 (0)