Skip to content

Commit

Permalink
Merge pull request #39 from THEOplayer/feature/conviva/error_details
Browse files Browse the repository at this point in the history
Feature/conviva/error details
  • Loading branch information
tvanlaerhoven authored Oct 15, 2024
2 parents 3bcd232 + 2660d46 commit 83e07a4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.theoplayer.android.connector.analytics.conviva.utils.calculateBufferL
import com.theoplayer.android.connector.analytics.conviva.utils.calculateConvivaOptions
import com.theoplayer.android.connector.analytics.conviva.utils.collectContentMetadata
import com.theoplayer.android.connector.analytics.conviva.utils.collectPlayerInfo
import com.theoplayer.android.connector.analytics.conviva.utils.flattenErrorObject
import java.lang.Double.isFinite

private const val TAG = "ConvivaHandler"
Expand Down Expand Up @@ -138,9 +139,17 @@ class ConvivaHandler(
if (BuildConfig.DEBUG) {
Log.d(TAG, "onError: ${event.errorObject.message}")
}

val error = event.errorObject
// Report error details in a separate event, which should be passed a flat <String, String> map.
val errorDetails = flattenErrorObject(error)
if (errorDetails.isNotEmpty()) {
convivaVideoAnalytics.reportPlaybackEvent("ErrorDetailsEvent", errorDetails)
}

// Report error and cleanup immediately.
// The contentInfo provides metadata for the failed video.
reportPlaybackFailed(event.errorObject.message ?: "Fatal error occurred")
reportPlaybackFailed(error.message ?: "Fatal error occurred")
}

onSegmentNotFound = EventListener<SegmentNotFoundEvent> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.conviva.sdk.ConvivaSdkConstants
import com.theoplayer.android.api.THEOplayerGlobal
import com.theoplayer.android.api.ads.AdBreak
import com.theoplayer.android.api.ads.GoogleImaAd
import com.theoplayer.android.api.error.THEOplayerException
import com.theoplayer.android.api.player.Player
import com.theoplayer.android.connector.analytics.conviva.ConvivaConfiguration
import com.theoplayer.android.connector.analytics.conviva.ConvivaMetadata
Expand Down Expand Up @@ -158,4 +159,14 @@ fun calculateBufferLength(player: Player): Long {
}
}
return (1e3 * bufferLength).toLong()
}
}

fun flattenErrorObject(error: THEOplayerException): Map<String, String> {
return mapOf(
"code" to error.code.name,
"category" to error.category.name,
"stack" to (error.stackTraceToString()),
"cause.stack" to (error.cause?.stackTraceToString() ?: ""),
"cause.message" to (error.cause?.message ?: "")
).filterValues { it != "" } // Remove entries with empty values
}

0 comments on commit 83e07a4

Please sign in to comment.