Fix RemoteConfigLoader to use Kotlin's built-in Result type
Changed from custom Result sealed class to kotlin.Result which has proper success/failure factory methods. Updated pattern matching to use getOrElse for cleaner error handling. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -24,7 +24,7 @@ object RemoteConfigLoader {
|
||||
suspend fun fetchConfig(
|
||||
remoteSettings: RemoteConfigSettings,
|
||||
userId: String? = null
|
||||
): Result<AppConfig> = withContext(Dispatchers.IO) {
|
||||
): kotlin.Result<AppConfig> = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val url = buildConfigUrl(remoteSettings, userId)
|
||||
Log.i(TAG, "Fetching config from: $url")
|
||||
@@ -50,15 +50,15 @@ object RemoteConfigLoader {
|
||||
val config = json.decodeFromString<AppConfig>(response)
|
||||
|
||||
Log.i(TAG, "Successfully loaded remote config for: ${config.appName}")
|
||||
Result.success(config)
|
||||
kotlin.Result.success(config)
|
||||
} else {
|
||||
val error = "HTTP $responseCode: ${connection.responseMessage}"
|
||||
Log.e(TAG, "Failed to fetch config: $error")
|
||||
Result.failure(Exception(error))
|
||||
kotlin.Result.failure(Exception(error))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error fetching remote config", e)
|
||||
Result.failure(e)
|
||||
kotlin.Result.failure(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,14 +98,12 @@ object RemoteConfigLoader {
|
||||
}
|
||||
|
||||
// Fetch remote config
|
||||
return when (val result = fetchConfig(remoteSettings, userId)) {
|
||||
is Result.Success -> {
|
||||
Log.i(TAG, "Using remote configuration")
|
||||
result.value
|
||||
}
|
||||
is Result.Failure -> {
|
||||
Log.w(TAG, "Remote config failed, falling back to local", result.error)
|
||||
return fetchConfig(remoteSettings, userId).getOrElse { error ->
|
||||
Log.w(TAG, "Remote config failed, falling back to local", error)
|
||||
localConfig
|
||||
}.also {
|
||||
if (it != localConfig) {
|
||||
Log.i(TAG, "Using remote configuration")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,8 +112,3 @@ object RemoteConfigLoader {
|
||||
private const val TAG = "RemoteConfigLoader"
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Result<out T> {
|
||||
data class Success<T>(val value: T) : Result<T>()
|
||||
data class Failure(val error: Exception) : Result<Nothing>()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user