From 89ebfd700375b8e10577ed74d8eedc6488bc8a18 Mon Sep 17 00:00:00 2001 From: lianbenjamin <79077248+lianbenjamin@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:47:39 +0300 Subject: [PATCH] feat(FEC-13652): add meaningful error message --- src/kaltura-player.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/kaltura-player.ts b/src/kaltura-player.ts index e5b29e0bb..317100b99 100644 --- a/src/kaltura-player.ts +++ b/src/kaltura-player.ts @@ -170,12 +170,31 @@ export class KalturaPlayer extends FakeEventTarget { this.setMedia(mediaConfig); return mediaConfig; } catch (e) { - const error = new Error(Error.Severity.CRITICAL, Error.Category.PLAYER, Error.Code.LOAD_FAILED, e); + const category = this._getErrorCategory(e); + const error = new Error(Error.Severity.CRITICAL, category, Error.Code.LOAD_FAILED, e); this._localPlayer.dispatchEvent(new FakeEvent(CoreEventType.ERROR, error)); throw e; } } + private _getErrorCategory(error: Error): number { + if (error.category === 2) { // category is Service from provider - BE issue + if (error.code === 2001) { // block action + const code = error.data?.messages ? error.data?.messages[0].code : ''; + if (code === 'SESSION_RESTRICTED') { + return Error.Category.MEDIA_UNAVAILABLE; + } + if (code === 'COUNTRY_RESTRICTED') { + return Error.Category.GEO_LOCATION; + } + } + if (error.code === 2002) { // media is not ready + return Error.Category.MEDIA_NOT_READY; + } + } + return Error.Category.PLAYER; + } + public setMedia(mediaConfig: KPMediaConfig): void { KalturaPlayer._logger.debug('setMedia', mediaConfig); this.reset(true);