Skip to content

Commit 0e311be

Browse files
committed
fix(pillarbox-monitoring): inconsistent error name value
Fixes #283, by modifying the value of the error name sent, allowing clearer errors when consumed by other tools. This modification supports the properties as defined by the WHATWG as well as the two custom properties provided by video.js which are `MEDIA_ERR_CUSTOM` and `MEDIA_ERR_ENCRYPTED`. - add a static method for setting the value of the error name - add mock for `MediaError`
1 parent 13acd7c commit 0e311be

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/trackers/PillarboxMonitoring.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class PillarboxMonitoring {
246246
log: JSON
247247
.stringify(error.metadata || pillarbox.log.history().slice(-15)),
248248
message: error.message,
249-
name: error.code,
249+
name: PillarboxMonitoring.errorKeyCode(error.code),
250250
...playbackPosition,
251251
url
252252
});
@@ -815,6 +815,25 @@ class PillarboxMonitoring {
815815
};
816816
}
817817

818+
/**
819+
* Returns a string representing the error key combined with its error code.
820+
*
821+
* If the error code doesn't exist the error key undefined.
822+
*
823+
* @param {number} code The error code
824+
*
825+
* @returns {string} The error key combined with its error code
826+
*/
827+
static errorKeyCode(code) {
828+
const error = [
829+
'MEDIA_ERR_CUSTOM',
830+
...Object.keys(window.MediaError),
831+
'MEDIA_ERR_ENCRYPTED'
832+
];
833+
834+
return `${error[code]}: ${code}`;
835+
}
836+
818837
/**
819838
* Generates a new session ID.
820839
*

test/trackers/pillarbox-monitoring.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('PillarboxMonitoring', () => {
77
let monitoring;
88

99
global.navigator.sendBeacon = jest.fn();
10+
global.window.MediaError = jest.fn().mockReturnValue({ });
1011

1112
beforeEach(() => {
1213
player = playerMock();

0 commit comments

Comments
 (0)