Commit 5981a921 authored by James Hugman's avatar James Hugman Committed by Christian Sadilek
Browse files

Re-instate catch-all to withExperiment

parent d53d2195
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
package org.mozilla.fenix.ext

import mozilla.components.service.nimbus.NimbusApi
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.experiments.nimbus.Variables
import org.mozilla.fenix.experiments.FeatureId

@@ -20,7 +21,7 @@ import org.mozilla.fenix.experiments.FeatureId
 * is passed a `null`.
 */
fun <T> NimbusApi.withExperiment(featureId: FeatureId, transform: (String?) -> T): T {
    return transform(getExperimentBranch(featureId.jsonName))
    return transform(withExperiment(featureId))
}

/**
@@ -29,7 +30,12 @@ fun <T> NimbusApi.withExperiment(featureId: FeatureId, transform: (String?) -> T
 * Short-hand for ` org.mozilla.experiments.nimbus.NimbusApi.getExperimentBranch`.
 */
fun NimbusApi.withExperiment(featureId: FeatureId) =
    try {
        getExperimentBranch(featureId.jsonName)
    } catch (e: Throwable) {
        Logger.error("Failed to getExperimentBranch(${featureId.jsonName})", e)
        null
    }

/**
 * Get the variables needed to configure the feature given by `featureId`.