From 5460685631a3b4e43daf7a40565436430b65f2b5 Mon Sep 17 00:00:00 2001 From: Tom Van Laerhoven Date: Wed, 9 Oct 2024 15:11:11 +0200 Subject: [PATCH 1/3] Provide extra error info in details event --- conviva/src/integration/ConvivaHandler.ts | 20 ++++++--------- conviva/src/utils/Utils.ts | 30 +++++++++++++---------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/conviva/src/integration/ConvivaHandler.ts b/conviva/src/integration/ConvivaHandler.ts index e2642952..93c3bf18 100644 --- a/conviva/src/integration/ConvivaHandler.ts +++ b/conviva/src/integration/ConvivaHandler.ts @@ -14,11 +14,12 @@ import { collectContentMetadata, collectDeviceMetadata, collectPlayerInfo, - flattenAndStringifyObject + flattenErrorObject } from '../utils/Utils'; import { AdReporter } from './ads/AdReporter'; import { YospaceAdReporter } from './ads/YospaceAdReporter'; import { VerizonAdReporter } from './ads/VerizonAdReporter'; +import { ErrorEvent } from 'theoplayer'; export interface ConvivaConfiguration { customerKey: string; @@ -279,25 +280,18 @@ export class ConvivaHandler { this.convivaVideoAnalytics?.reportPlaybackMetric(Constants.Playback.SEEK_ENDED); }; - private readonly onError = () => { + private readonly onError = (errorEvent: ErrorEvent) => { const metadata: ConvivaMetadata = {}; if (Number.isNaN(this.player.duration)) { metadata[Constants.DURATION] = -1; } - const error = this.player.errorObject; + const error = errorEvent.errorObject; // Optionally report error details, which should be a flat {[key: string]: string} object. - if (error?.cause) { - try { - const errorDetails = flattenAndStringifyObject(error?.cause); - if (Object.keys(errorDetails).length > 0) { - this.convivaVideoAnalytics?.reportPlaybackEvent('ErrorDetailsEvent', errorDetails); - } - } catch (ignore) { - // Failed to stringify body - } + const errorDetails: Record = flattenErrorObject(error); + if (Object.keys(errorDetails).length > 0) { + this.convivaVideoAnalytics?.reportPlaybackEvent('ErrorDetailsEvent', errorDetails); } - this.convivaVideoAnalytics?.reportPlaybackFailed(error?.message ?? 'Fatal error occurred', metadata); this.releaseSession(); diff --git a/conviva/src/utils/Utils.ts b/conviva/src/utils/Utils.ts index a1496621..569b10e6 100644 --- a/conviva/src/utils/Utils.ts +++ b/conviva/src/utils/Utils.ts @@ -14,6 +14,9 @@ import { type GoogleImaAd, type VerizonMediaAd, type VerizonMediaAdBreak, + type THEOplayerError, + ErrorCategory, + ErrorCode, version } from 'theoplayer'; import { ConvivaConfiguration } from '../integration/ConvivaHandler'; @@ -220,18 +223,19 @@ export function calculateBufferLength(player: ChromelessPlayer): number { return bufferLength * 1000; } -export function flattenAndStringifyObject(obj: any): { [key: string]: string } { - const result: Record = {}; - Object.keys(obj).forEach((key) => { - try { - if (typeof obj[key] === 'object' && obj[key] !== null) { - result[key] = JSON.stringify(obj[key]); - } else { - result[key] = obj[key].toString(); - } - } catch (ignore) { - // Failed to stringify value. +export function flattenErrorObject(error?: THEOplayerError): { [key: string]: string } { + const errorDetails: Record = { + code: ErrorCode[error?.code ?? -1], + category: ErrorCategory[error?.category ?? -1], + name: error?.cause?.name, + message: error?.cause?.message, + stack: error?.stack + }; + // Remove undefined values + for (const key in errorDetails) { + if (errorDetails[key] === undefined) { + delete errorDetails[key]; } - }); - return result; + } + return errorDetails; } From e874436c173cea86cc443604102c17bf90c7d39f Mon Sep 17 00:00:00 2001 From: Tom Van Laerhoven Date: Wed, 9 Oct 2024 15:15:26 +0200 Subject: [PATCH 2/3] Add changeset --- .changeset/green-mugs-obey.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/green-mugs-obey.md diff --git a/.changeset/green-mugs-obey.md b/.changeset/green-mugs-obey.md new file mode 100644 index 00000000..df490d1d --- /dev/null +++ b/.changeset/green-mugs-obey.md @@ -0,0 +1,5 @@ +--- +"@theoplayer/conviva-connector-web": minor +--- + +Added additional error details on playback failure. From 69055eb007c61c5160e70574f5bed892e920f70c Mon Sep 17 00:00:00 2001 From: Tom Van Laerhoven Date: Mon, 14 Oct 2024 10:40:22 +0200 Subject: [PATCH 3/3] Update typings --- conviva/src/utils/Utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conviva/src/utils/Utils.ts b/conviva/src/utils/Utils.ts index 569b10e6..1132f81c 100644 --- a/conviva/src/utils/Utils.ts +++ b/conviva/src/utils/Utils.ts @@ -224,7 +224,7 @@ export function calculateBufferLength(player: ChromelessPlayer): number { } export function flattenErrorObject(error?: THEOplayerError): { [key: string]: string } { - const errorDetails: Record = { + const errorDetails: { [key: string]: string | undefined } = { code: ErrorCode[error?.code ?? -1], category: ErrorCategory[error?.category ?? -1], name: error?.cause?.name, @@ -237,5 +237,5 @@ export function flattenErrorObject(error?: THEOplayerError): { [key: string]: st delete errorDetails[key]; } } - return errorDetails; + return errorDetails as { [key: string]: string }; }