Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0.0] Differentiate login errors and add logs #1841

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading