diff --git a/src/trackers/PillarboxMonitoring.js b/src/trackers/PillarboxMonitoring.js index 20b1a02..1374d4e 100644 --- a/src/trackers/PillarboxMonitoring.js +++ b/src/trackers/PillarboxMonitoring.js @@ -246,7 +246,7 @@ class PillarboxMonitoring { log: JSON .stringify(error.metadata || pillarbox.log.history().slice(-15)), message: error.message, - name: error.code, + name: PillarboxMonitoring.errorKeyCode(error.code), ...playbackPosition, url }); @@ -815,6 +815,25 @@ class PillarboxMonitoring { }; } + /** + * Returns a string representing the error key combined with its error code. + * + * If the error code doesn't exist the error key undefined. + * + * @param {number} code The error code + * + * @returns {string} The error key combined with its error code + */ + static errorKeyCode(code) { + const error = [ + 'MEDIA_ERR_CUSTOM', + ...Object.keys(window.MediaError), + 'MEDIA_ERR_ENCRYPTED' + ]; + + return `${error[code]}: ${code}`; + } + /** * Generates a new session ID. * diff --git a/test/trackers/pillarbox-monitoring.spec.js b/test/trackers/pillarbox-monitoring.spec.js index 063b1d7..e4ba736 100644 --- a/test/trackers/pillarbox-monitoring.spec.js +++ b/test/trackers/pillarbox-monitoring.spec.js @@ -7,6 +7,7 @@ describe('PillarboxMonitoring', () => { let monitoring; global.navigator.sendBeacon = jest.fn(); + global.window.MediaError = jest.fn().mockReturnValue({ }); beforeEach(() => { player = playerMock();