Skip to content

Commit

Permalink
feat: update errorHandler to support the same classes as in Swift. (#236
Browse files Browse the repository at this point in the history
)
  • Loading branch information
didiergarcia authored Oct 4, 2024
1 parent d37d2d3 commit 745c7a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions core/src/main/java/com/segment/analytics/kotlin/core/Errors.kt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 745c7a4

Please sign in to comment.