Skip to content

Commit

Permalink
Differentiate login failure cases
Browse files Browse the repository at this point in the history
* The implementation of login with external_id has not changed
* Add new ExecutionResult type of FAIL_CONFLICT to differentiate this case from general failure case of FAIL_NORETRY
* Add logs for both type of responses, but still try to create the user on both failures (as before)
  • Loading branch information
nan-li authored and jinliu9508 committed Jan 31, 2024
1 parent 8f7063f commit a54fac2
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 a54fac2

Please sign in to comment.