diff --git a/modules/tripleliftBidAdapter.js b/modules/tripleliftBidAdapter.js index 830d26eda61..7e964661db6 100644 --- a/modules/tripleliftBidAdapter.js +++ b/modules/tripleliftBidAdapter.js @@ -1,4 +1,4 @@ -import { tryAppendQueryString, logMessage, isEmpty, isStr, isPlainObject, isArray, logWarn } from '../src/utils.js'; +import { tryAppendQueryString, logMessage, logError, isEmpty, isStr, isPlainObject, isArray, logWarn } from '../src/utils.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; @@ -175,14 +175,18 @@ function _getORTBVideo(bidRequest) { function _getFloor (bid) { let floor = null; if (typeof bid.getFloor === 'function') { - const floorInfo = bid.getFloor({ - currency: 'USD', - mediaType: _isInstreamBidRequest(bid) ? 'video' : 'banner', - size: '*' - }); - if (typeof floorInfo === 'object' && - floorInfo.currency === 'USD' && !isNaN(parseFloat(floorInfo.floor))) { - floor = parseFloat(floorInfo.floor); + try { + const floorInfo = bid.getFloor({ + currency: 'USD', + mediaType: _isInstreamBidRequest(bid) ? 'video' : 'banner', + size: '*' + }); + if (typeof floorInfo === 'object' && + floorInfo.currency === 'USD' && !isNaN(parseFloat(floorInfo.floor))) { + floor = parseFloat(floorInfo.floor); + } + } catch (err) { + logError('Triplelift: getFloor threw an error: ', err); } } return floor !== null ? floor : bid.params.floor; diff --git a/test/spec/modules/tripleliftBidAdapter_spec.js b/test/spec/modules/tripleliftBidAdapter_spec.js index 164188804a3..fc33a7cd676 100644 --- a/test/spec/modules/tripleliftBidAdapter_spec.js +++ b/test/spec/modules/tripleliftBidAdapter_spec.js @@ -11,8 +11,7 @@ const GDPR_CONSENT_STR = 'BOONm0NOONm0NABABAENAa-AAAARh7______b9_3__7_9uz_Kv_K7V describe('triplelift adapter', function () { const adapter = newBidder(tripleliftAdapterSpec); - let bid, instreamBid; - let sandbox; + let bid, instreamBid, sandbox, logErrorSpy; this.beforeEach(() => { bid = { @@ -379,9 +378,11 @@ describe('triplelift adapter', function () { }, }; sandbox = sinon.sandbox.create(); + logErrorSpy = sinon.spy(utils, 'logError'); }); afterEach(() => { sandbox.restore(); + utils.logError.restore(); }); it('exists and is an object', function () { @@ -787,6 +788,15 @@ describe('triplelift adapter', function () { size: '*' })).to.be.true; }); + it('should catch error if getFloor throws error', function() { + bidRequests[0].getFloor = () => { + throw new Error('An exception!'); + }; + + tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); + + expect(logErrorSpy.calledOnce).to.equal(true); + }); it('should send global config fpd if kvps are available', function() { const sens = null; const category = ['news', 'weather', 'hurricane'];