Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rubicon Bid Adapter: Handle floor errors #5628

Merged
merged 1 commit into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,16 @@ export const spec = {

let bidFloor;
if (typeof bidRequest.getFloor === 'function' && !config.getConfig('rubicon.disableFloors')) {
let floorInfo = bidRequest.getFloor({
currency: 'USD',
mediaType: 'video',
size: parseSizes(bidRequest, 'video')
});
let floorInfo;
try {
floorInfo = bidRequest.getFloor({
currency: 'USD',
mediaType: 'video',
size: parseSizes(bidRequest, 'video')
});
} catch (e) {
utils.logError('Rubicon: getFloor threw an error: ', e);
}
bidFloor = typeof floorInfo === 'object' && floorInfo.currency === 'USD' && !isNaN(parseInt(floorInfo.floor)) ? parseFloat(floorInfo.floor) : undefined;
} else {
bidFloor = parseFloat(utils.deepAccess(bidRequest, 'params.floor'));
Expand Down Expand Up @@ -527,11 +532,16 @@ export const spec = {

// If floors module is enabled and we get USD floor back, send it in rp_hard_floor else undfined
if (typeof bidRequest.getFloor === 'function' && !config.getConfig('rubicon.disableFloors')) {
let floorInfo = bidRequest.getFloor({
currency: 'USD',
mediaType: 'banner',
size: '*'
});
let floorInfo;
try {
floorInfo = bidRequest.getFloor({
currency: 'USD',
mediaType: 'video',
size: parseSizes(bidRequest, 'video')
});
} catch (e) {
utils.logError('Rubicon: getFloor threw an error: ', e);
}
data['rp_hard_floor'] = typeof floorInfo === 'object' && floorInfo.currency === 'USD' && !isNaN(parseInt(floorInfo.floor)) ? floorInfo.floor : undefined;
}

Expand Down
29 changes: 28 additions & 1 deletion test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ describe('the rubicon adapter', function () {
let sandbox,
bidderRequest,
sizeMap,
getFloorResponse;
getFloorResponse,
logErrorSpy;

/**
* @typedef {Object} sizeMapConverted
Expand Down Expand Up @@ -272,6 +273,7 @@ describe('the rubicon adapter', function () {

beforeEach(function () {
sandbox = sinon.sandbox.create();
logErrorSpy = sinon.spy(utils, 'logError');
getFloorResponse = {};
bidderRequest = {
bidderCode: 'rubicon',
Expand Down Expand Up @@ -343,6 +345,7 @@ describe('the rubicon adapter', function () {

afterEach(function () {
sandbox.restore();
utils.logError.restore();
});

describe('MAS mapping / ordering', function () {
Expand Down Expand Up @@ -1597,6 +1600,30 @@ describe('the rubicon adapter', function () {
[request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
expect(request.data.imp[0].bidfloor).to.equal(1.23);
});

it('should continue with auction and log error if getFloor throws one', function () {
createVideoBidderRequest();
// default getFloor response is empty object so should not break and not send hard_floor
bidderRequest.bids[0].getFloor = () => {
throw new Error('An exception!');
};
sandbox.stub(Date, 'now').callsFake(() =>
bidderRequest.auctionStart + 100
);

let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);

// log error called
expect(logErrorSpy.calledOnce).to.equal(true);

// should have an imp
expect(request.data.imp).to.exist.and.to.be.a('array');
expect(request.data.imp).to.have.lengthOf(1);

// should be NO bidFloor
expect(request.data.imp[0].bidfloor).to.be.undefined;
});

it('should add alias name to PBS Request', function() {
createVideoBidderRequest();

Expand Down