Skip to content

Commit 9a5c959

Browse files
authored
Merge pull request #1841 from OneSignal/user_model/add_login_409_logs
[5.0.0] Differentiate login errors and add logs
2 parents 2e04cd1 + b4de371 commit 9a5c959

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/operations/IOperationExecutor.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,10 @@ enum class ExecutionResult {
6868
* retried if authorization can be achieved.
6969
*/
7070
FAIL_UNAUTHORIZED,
71+
72+
/**
73+
* Used in special login case.
74+
* The operation failed due to a conflict and can be handled.
75+
*/
76+
FAIL_CONFLICT,
7177
}

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/operations/impl/OperationRepo.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ internal class OperationRepo(
167167
}
168168
ExecutionResult.FAIL_UNAUTHORIZED, // TODO: Need to provide callback for app to reset JWT. For now, fail with no retry.
169169
ExecutionResult.FAIL_NORETRY,
170+
ExecutionResult.FAIL_CONFLICT,
170171
-> {
171172
Logging.error("Operation execution failed without retry: $operations")
172173
// on failure we remove the operation from the store and wake any waiters

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/IdentityOperationExecutor.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ internal class IdentityOperationExecutor(
5151
return when (responseType) {
5252
NetworkUtils.ResponseStatusType.RETRYABLE ->
5353
ExecutionResponse(ExecutionResult.FAIL_RETRY)
54-
NetworkUtils.ResponseStatusType.INVALID,
55-
NetworkUtils.ResponseStatusType.CONFLICT,
56-
->
54+
NetworkUtils.ResponseStatusType.INVALID ->
5755
ExecutionResponse(ExecutionResult.FAIL_NORETRY)
56+
NetworkUtils.ResponseStatusType.CONFLICT ->
57+
ExecutionResponse(ExecutionResult.FAIL_CONFLICT)
5858
NetworkUtils.ResponseStatusType.UNAUTHORIZED ->
5959
ExecutionResponse(ExecutionResult.FAIL_UNAUTHORIZED)
6060
NetworkUtils.ResponseStatusType.MISSING -> {

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/LoginUserOperationExecutor.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,16 @@ internal class LoginUserOperationExecutor(
8686

8787
ExecutionResponse(ExecutionResult.SUCCESS_STARTING_ONLY, mapOf(loginUserOp.onesignalId to backendOneSignalId))
8888
}
89+
ExecutionResult.FAIL_CONFLICT -> {
90+
// When the SetAliasOperation fails with conflict that *most likely* means the externalId provided
91+
// is already associated to a user. This *expected* condition means we must create a user.
92+
// We hardcode the response of "user-2" in the log to provide information to the SDK consumer
93+
Logging.debug("LoginUserOperationExecutor now handling 409 response with \"code\": \"user-2\" by switching to user with \"external_id\": \"${loginUserOp.externalId}\"")
94+
createUser(loginUserOp, operations)
95+
}
8996
ExecutionResult.FAIL_NORETRY -> {
90-
// When the SetAliasOperation fails without retry that *most likely* means the externalId provided
91-
// is already associated to a user. This expected condition means we must create a user.
97+
// Some other failure occurred, still try to recover by creating the user
98+
Logging.error("LoginUserOperationExecutor encountered error. Attempt to recover by switching to user with \"external_id\": \"${loginUserOp.externalId}\"")
9299
createUser(loginUserOp, operations)
93100
}
94101
else -> ExecutionResponse(result.result)

0 commit comments

Comments
 (0)