Skip to content

Commit

Permalink
fix(FEC-7516): fix IMA get stuck when ad response is bad (#36)
Browse files Browse the repository at this point in the history
when ad response is malformed we get a rejection of promise, but because int's a nested promise and we didn't `return` it then the external `catch` didn't get triggered and the code flow got stuck.
  • Loading branch information
OrenMe authored Dec 3, 2017
1 parent 66fb487 commit 52fca41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ima-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class ImaMiddleware extends BaseMiddleware {
case State.LOADED: {
const initialUserAction = this._context.initialUserAction();
if (initialUserAction) {
initialUserAction.then(() => {
return initialUserAction.then(() => {
this.callNext(next);
});
} else {
Expand All @@ -65,7 +65,7 @@ export default class ImaMiddleware extends BaseMiddleware {
case State.PAUSED: {
const resumeAd = this._context.resumeAd();
if (resumeAd) {
resumeAd.then(() => {
return resumeAd.then(() => {
this.callNext(next);
});
} else {
Expand Down
12 changes: 12 additions & 0 deletions test/src/ima-middleware.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ describe('Ima Middleware', function () {
});
});

it('should destory adsManager and resume playback in case of error', function (done) {
let spy = sandbox.spy(fakeContext, 'destroy');
fakeContext.setCurrentState(State.LOADED);
fakeContext.initialUserAction = Promise.reject();
imaMiddleware = new ImaMiddleware(fakeContext);
imaMiddleware.play(function () {
spy.should.have.been.calledOnce;
fakeContext.initialUserAction = Promise.resolve();
done();
});
});

it('should resumeAd', function (done) {
let spy = sandbox.spy(fakeContext, 'resumeAd');
fakeContext.setCurrentState(State.PAUSED);
Expand Down

0 comments on commit 52fca41

Please sign in to comment.