From 4192f2c2c0445ba2b894cb00bb9975977b3e3392 Mon Sep 17 00:00:00 2001 From: Didier Garcia Date: Fri, 4 Oct 2024 01:04:20 -0400 Subject: [PATCH] feat: update errorHandler to support the same classes as in Swift. --- .../segment/analytics/kotlin/core/Errors.kt | 20 +++++++++++++++++++ .../segment/analytics/kotlin/core/Settings.kt | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/segment/analytics/kotlin/core/Errors.kt b/core/src/main/java/com/segment/analytics/kotlin/core/Errors.kt index bf538464..ef2348c6 100644 --- a/core/src/main/java/com/segment/analytics/kotlin/core/Errors.kt +++ b/core/src/main/java/com/segment/analytics/kotlin/core/Errors.kt @@ -1,6 +1,26 @@ package com.segment.analytics.kotlin.core import com.segment.analytics.kotlin.core.platform.plugins.logger.segmentLog +sealed class AnalyticsError(): Throwable() { + data class StorageUnableToCreate(override val message: String?): AnalyticsError() + data class StorageUnableToWrite(override val message: String?): AnalyticsError() + data class StorageUnableToRename(override val message: String?): AnalyticsError() + data class StorageUnableToOpen(override val message: String?): AnalyticsError() + data class StorageUnableToClose(override val message: String?): AnalyticsError() + data class StorageInvalid(override val message: String?): AnalyticsError() + data class StorageUnknown(override val message: String?, override val cause: Throwable?): AnalyticsError() + data class NetworkUnexpectedHTTPCode(override val message: String?): AnalyticsError() + data class NetworkServerLimited(override val message: String?): AnalyticsError() + data class NetworkServerRejected(override val message: String?): AnalyticsError() + data class NetworkUnknown(override val message: String?, override val cause: Throwable?): AnalyticsError() + data class NetworkInvalidData(override val message: String?): AnalyticsError() + data class JsonUnableToSerialize(override val message: String?, override val cause: Throwable?): AnalyticsError() + data class JsonUnableToDeserialize(override val message: String?, override val cause: Throwable?): AnalyticsError() + data class JsonUnknown(override val message: String?, override val cause: Throwable?): AnalyticsError() + data class PluginError(override val message: String?, override val cause: Throwable?): AnalyticsError() + data class EnrichmentError(override val message: String?): AnalyticsError() + data class SettingsFetchError(override val message: String?, override val cause: Throwable?): AnalyticsError() +} /** * Reports an internal error to the user-defined error handler. diff --git a/core/src/main/java/com/segment/analytics/kotlin/core/Settings.kt b/core/src/main/java/com/segment/analytics/kotlin/core/Settings.kt index d4db087c..97799fb4 100644 --- a/core/src/main/java/com/segment/analytics/kotlin/core/Settings.kt +++ b/core/src/main/java/com/segment/analytics/kotlin/core/Settings.kt @@ -115,7 +115,7 @@ internal fun Analytics.fetchSettings( log("Fetched Settings: $settingsString") LenientJson.decodeFromString(settingsString) } catch (ex: Exception) { - reportErrorWithMetrics(this, ex, "Failed to fetch settings", + reportErrorWithMetrics(this, AnalyticsError.SettingsFetchError(ex.message, ex), "Failed to fetch settings", Telemetry.INVOKE_ERROR_METRIC, ex.stackTraceToString()) { it["error"] = ex.toString() it["writekey"] = writeKey