Skip to content

Commit

Permalink
fix: CohortTooLargeException not thrown when in proxy mode (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiuhc authored Nov 1, 2024
1 parent b5e0684 commit cc10582
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/kotlin/cohort/CohortApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import okhttp3.OkHttpClient
import java.util.Base64
import java.util.concurrent.ExecutionException

internal class CohortTooLargeException(cohortId: String, maxCohortSize: Int) : RuntimeException(
open class CohortTooLargeException(cohortId: String, maxCohortSize: Int) : RuntimeException(
"Cohort $cohortId exceeds the maximum cohort size defined in the SDK configuration $maxCohortSize"
)

internal class ProxyCohortTooLargeException(cohortId: String, maxCohortSize: Int) :
CohortTooLargeException(cohortId, maxCohortSize)

internal class CohortNotModifiedException(cohortId: String) : RuntimeException(
"Cohort $cohortId has not been modified."
)
Expand Down Expand Up @@ -68,11 +71,15 @@ internal class DynamicCohortApi(
} catch (e: CohortNotModifiedException) {
throw e
} catch (e: CohortTooLargeException) {
throw e
throw ProxyCohortTooLargeException(cohortId, maxCohortSize)
} catch (e: Exception) {
Logger.w("Downloading cohort $cohortId from proxy failed. Falling back to Amplitude.", e)
metrics.onCohortDownloadOriginFallback(e)
getCohort(serverUrl, cohortId, cohort)
try {
getCohort(serverUrl, cohortId, cohort)
} catch (e: CohortTooLargeException) {
throw ProxyCohortTooLargeException(cohortId, maxCohortSize)
}
}
} else {
getCohort(serverUrl, cohortId, cohort)
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/cohort/CohortLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ internal class CohortLoader(
cohortStorage.putCohort(cohort)
} catch (e: CohortNotModifiedException) {
// Do nothing
} catch (e: ProxyCohortTooLargeException) {
// Do nothing
} catch (e: CohortTooLargeException) {
metrics.onCohortDownloadTooLarge(e)
throw e
Expand Down

0 comments on commit cc10582

Please sign in to comment.