Skip to content

Commit

Permalink
feat(FEC-9071): add errorDetails field to kava error reporting (#34)
Browse files Browse the repository at this point in the history
* feat(FEC-9071): add errorDetails field to kava error reporting

* FEC-9071 - move stringify to kava-model and wrap in try catch. when no details then errorDetails will be an empty string

* fix unit tests
  • Loading branch information
RoyBregman authored Jun 13, 2019
1 parent 09fcf22 commit 67ca77e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/kava-event-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ export const KavaEventModel: {[event: string]: KavaEvent} = {
type: 'ERROR',
index: 98,
getEventModel: (model: KavaModel) => ({
errorCode: model.getErrorCode()
errorCode: model.getErrorCode(),
errorDetails: model.getErrorDetails()
})
}
};
Expand Down
19 changes: 19 additions & 0 deletions src/kava-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class KavaModel {
language: string;
caption: string;
errorCode: number;
errorDetails: any;
joinTime: number;
canPlayTime: number;
targetPosition: number;
Expand Down Expand Up @@ -130,6 +131,24 @@ class KavaModel {
return this.errorCode;
}

/**
* Gets the error additional data.
* @returns {string} - The stringifyed error data.
* @memberof KavaModel
* @instance
*/
getErrorDetails(): string {
let retVal: string = '';
if (this.errorDetails) {
try {
retVal = JSON.stringify(this.errorDetails);
} catch (e) {
// do nothing
}
}
return retVal;
}

/**
* Gets the event index counter.
* @returns {number} - The event index counter.
Expand Down
2 changes: 1 addition & 1 deletion src/kava.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ class Kava extends BasePlugin {

_onError(event: FakeEvent): void {
if (event.payload && event.payload.severity === PKError.Severity.CRITICAL) {
this._model.updateModel({errorCode: event.payload.code});
this._model.updateModel({errorCode: event.payload.code, errorDetails: event.payload.data});
this._sendAnalytics(KavaEventModel.ERROR);
this.reset();
}
Expand Down
7 changes: 6 additions & 1 deletion test/src/kava-event-model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class FakeModel {
return 200;
}

getErrorDetails() {
return {};
}

getActualBitrate() {
return 720;
}
Expand Down Expand Up @@ -177,7 +181,8 @@ describe('KavaEventModel', () => {
KavaEventModel.ERROR.type.should.equal('ERROR');
KavaEventModel.ERROR.index.should.equal(98);
KavaEventModel.ERROR.getEventModel(fakeModel).should.deep.equal({
errorCode: fakeModel.getErrorCode()
errorCode: fakeModel.getErrorCode(),
errorDetails: fakeModel.getErrorDetails()
});
});

Expand Down

0 comments on commit 67ca77e

Please sign in to comment.