Skip to content

Commit 2305056

Browse files
committed
Return an error result for FirstSuccessfulStrategy rather than throwing
Signed-off-by: penguindan <[email protected]>
1 parent c299717 commit 2305056

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

kotlin-sdk/src/commonMain/kotlin/dev/openfeature/kotlin/sdk/multiprovider/FirstSuccessfulStrategy.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package dev.openfeature.kotlin.sdk.multiprovider
33
import dev.openfeature.kotlin.sdk.EvaluationContext
44
import dev.openfeature.kotlin.sdk.FeatureProvider
55
import dev.openfeature.kotlin.sdk.ProviderEvaluation
6+
import dev.openfeature.kotlin.sdk.Reason
7+
import dev.openfeature.kotlin.sdk.exceptions.ErrorCode
68
import dev.openfeature.kotlin.sdk.exceptions.OpenFeatureError
79

810
/**
911
* A [MultiProvider.Strategy] similar to the [FirstMatchStrategy], except that errors from evaluated
1012
* providers do not halt execution.
1113
*
12-
* If no provider successfully responds, it throws an error result.
14+
* If no provider successfully responds, it returns an error result.
1315
*/
1416
class FirstSuccessfulStrategy : MultiProvider.Strategy {
1517
override fun <T> evaluate(
@@ -40,6 +42,11 @@ class FirstSuccessfulStrategy : MultiProvider.Strategy {
4042

4143
// No provider returned a successful result, throw an error
4244
// This indicates that all providers either failed or had errors
43-
throw OpenFeatureError.GeneralError("No provider returned a successful evaluation for the requested flag.")
45+
return ProviderEvaluation(
46+
value = defaultValue,
47+
reason = Reason.DEFAULT.toString(),
48+
errorCode = ErrorCode.FLAG_NOT_FOUND,
49+
errorMessage = "No provider returned a successful evaluation for the requested flag."
50+
)
4451
}
4552
}

0 commit comments

Comments
 (0)