Skip to content

Commit

Permalink
Merge pull request #1841 from OneSignal/user_model/add_login_409_logs
Browse files Browse the repository at this point in the history
[5.0.0] Differentiate login errors and add logs
  • Loading branch information
emawby authored and jinliu9508 committed Feb 6, 2024
2 parents ae6e674 + ced0a42 commit dda60fa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ enum class ExecutionResult {
* retried if authorization can be achieved.
*/
FAIL_UNAUTHORIZED,

/**
* Used in special login case.
* The operation failed due to a conflict and can be handled.
*/
FAIL_CONFLICT,
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ internal class OperationRepo(
}
ExecutionResult.FAIL_UNAUTHORIZED, // TODO: Need to provide callback for app to reset JWT. For now, fail with no retry.
ExecutionResult.FAIL_NORETRY,
ExecutionResult.FAIL_CONFLICT,
-> {
Logging.error("Operation execution failed without retry: $operations")
// on failure we remove the operation from the store and wake any waiters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ internal class IdentityOperationExecutor(
return when (responseType) {
NetworkUtils.ResponseStatusType.RETRYABLE ->
ExecutionResponse(ExecutionResult.FAIL_RETRY)
NetworkUtils.ResponseStatusType.INVALID,
NetworkUtils.ResponseStatusType.CONFLICT,
->
NetworkUtils.ResponseStatusType.INVALID ->
ExecutionResponse(ExecutionResult.FAIL_NORETRY)
NetworkUtils.ResponseStatusType.CONFLICT ->
ExecutionResponse(ExecutionResult.FAIL_CONFLICT)
NetworkUtils.ResponseStatusType.UNAUTHORIZED ->
ExecutionResponse(ExecutionResult.FAIL_UNAUTHORIZED)
NetworkUtils.ResponseStatusType.MISSING -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,16 @@ internal class LoginUserOperationExecutor(

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

0 comments on commit dda60fa

Please sign in to comment.