Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update errorHandler to support the same classes as in Swift. #236

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading