Skip to content

Commit e1ed60a

Browse files
committed
explicitly check for 409 on Identify User response
* We were switching to the user when the Identify User request returns any failure, but we should really check that the code is `409` to go down this path. It could be some other error.
1 parent a5808c4 commit e1ed60a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,19 @@ class OSUserExecutor {
214214

215215
executePendingRequests() // TODO: Here or after fetch or after transfer?
216216

217-
} onFailure: { _ in
218-
// TODO: Actually account for error code when processing this failure response
217+
} onFailure: { error in
219218
// Returns 409 if any provided (label, id) pair exists on another User, so the SDK will switch to this user.
220-
// If 409:
221-
fetchUser(aliasLabel: OS_EXTERNAL_ID, aliasId: request.aliasId, identityModel: request.identityModelToUpdate)
222-
// TODO: Link ^ to the new user
223-
transferPushSubscriptionTo(aliasLabel: request.aliasLabel, aliasId: request.aliasId, retainPreviousUser: true) // update logic to determine flag
224-
executePendingRequests() // Here or after fetch or after transfer?
219+
if error?._code == 409 {
220+
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "executeIdentifyUserRequest returned 409, failed due to alias already assigned to a different user. Now switch to this user.")
225221

226-
// If not 409, we retry, depending on what the error is?
222+
fetchUser(aliasLabel: OS_EXTERNAL_ID, aliasId: request.aliasId, identityModel: request.identityModelToUpdate)
223+
// TODO: Link ^ to the new user... what was this todo for?
224+
transferPushSubscriptionTo(aliasLabel: request.aliasLabel, aliasId: request.aliasId, retainPreviousUser: true) // update logic to determine flag
225+
executePendingRequests() // Here or after fetch or after transfer?
226+
} else {
227+
// If not 409, we retry, depending on what the error is?
228+
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "executeIdentifyUserRequest failed without returning a 409.")
229+
}
227230
}
228231
}
229232

0 commit comments

Comments
 (0)