Skip to content

Commit

Permalink
Pass the error message back to the caller
Browse files Browse the repository at this point in the history
  • Loading branch information
lalwani committed Mar 26, 2024
1 parent 1f9872b commit 3d97d4c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ sealed class AuthException(override val message: String) : RuntimeException(mess

internal const val AUTH_CODE_INVALID = "Invalid auth code"

internal const val EMPTY_RESPONSE = "Response is empty"
internal const val AUTH_CODE_NOT_PRESENT = "Auth code is not present"

internal const val NULL_RESPONSE = "Response not received"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package com.uber.sdk2.auth.internal.sso

import android.content.Intent
import android.net.Uri
import android.util.Log
import android.provider.DocumentsContract.EXTRA_ERROR
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.VisibleForTesting
Expand Down Expand Up @@ -105,19 +105,15 @@ internal class UniversalSsoLink(
private fun handleResult(result: ActivityResult): String {
return when (result.resultCode) {
RESULT_OK -> {
Log.d("xxxx", result.data?.getStringExtra("CODE_RECEIVED").orEmpty())
result.data?.let {
if (!it.getStringExtra("CODE_RECEIVED").isNullOrEmpty()) {
it.getStringExtra("CODE_RECEIVED").orEmpty()
} else if (!it.getStringExtra("EXTRA_ERROR").isNullOrEmpty()) {
throw AuthException.ClientError(it.getStringExtra("EXTRA_ERROR").orEmpty())
} else {
throw AuthException.ClientError(AuthException.EMPTY_RESPONSE)
}
result.data?.getStringExtra(EXTRA_CODE_RECEIVED)?.ifEmpty {
throw AuthException.ClientError(AuthException.AUTH_CODE_NOT_PRESENT)
} ?: throw AuthException.ClientError(AuthException.NULL_RESPONSE)
}

RESULT_CANCELED -> {
throw AuthException.ClientError(AuthException.CANCELED)
result.data?.getStringExtra(EXTRA_ERROR)?.let {
throw AuthException.ClientError(it)
} ?: throw AuthException.ClientError(AuthException.CANCELED)
}
else -> {
// should never happen
Expand All @@ -133,5 +129,8 @@ internal class UniversalSsoLink(
companion object {
/** The response type constant for the SSO authentication. */
internal const val RESPONSE_TYPE = "code"

private const val EXTRA_CODE_RECEIVED = "CODE_RECEIVED"
private const val EXTRA_ERROR = "ERROR"
}
}

0 comments on commit 3d97d4c

Please sign in to comment.