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..2a326376532 100644 --- a/test/spec/modules/tripleliftBidAdapter_spec.js +++ b/test/spec/modules/tripleliftBidAdapter_spec.js @@ -787,6 +787,17 @@ describe('triplelift adapter', function () { size: '*' })).to.be.true; }); + it('should catch error if getFloor throws error', function() { + let logErrorSpy = sinon.spy(utils, 'logError'); + + 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'];