Skip to content

Commit 35dde95

Browse files
committed
Replace exceptions in PFUser.signUp with errors.
1 parent 38b46de commit 35dde95

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
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: 21 additions & 10 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
@@ -456,8 +469,7 @@ - (BFTask *)signUpAsync:(BFTask *)toAwait {
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)