Skip to content

Commit

Permalink
check if bidder exists before making request object (prebid#2695)
Browse files Browse the repository at this point in the history
* check if bidder exists before making request object

* remove redundant check
  • Loading branch information
jsnellbaker authored and dluxemburg committed Jul 17, 2018
1 parent b519552 commit 6637c7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
29 changes: 15 additions & 14 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ exports.makeBidRequests = function(adUnits, auctionStart, auctionId, cbTimeout,
auctionStart: auctionStart,
timeout: cbTimeout
};
if (bidderRequest.bids && bidderRequest.bids.length !== 0) {
const adapter = _bidderRegistry[bidderCode];
if (!adapter) {
utils.logError(`Trying to make a request for bidder that does not exist: ${bidderCode}`);
}

if (adapter && bidderRequest.bids && bidderRequest.bids.length !== 0) {
bidRequests.push(bidderRequest);
}
});
Expand Down Expand Up @@ -347,19 +352,15 @@ exports.callBids = (adUnits, bidRequests, addBidResponse, doneCb, requestCallbac
bidRequest.start = timestamp();
// TODO : Do we check for bid in pool from here and skip calling adapter again ?
const adapter = _bidderRegistry[bidRequest.bidderCode];
if (adapter) {
utils.logMessage(`CALLING BIDDER ======= ${bidRequest.bidderCode}`);
events.emit(CONSTANTS.EVENTS.BID_REQUESTED, bidRequest);
bidRequest.doneCbCallCount = 0;
let done = doneCb(bidRequest.bidderRequestId);
let ajax = ajaxBuilder(clientBidRequests[0].timeout, requestCallbacks ? {
request: requestCallbacks.request.bind(null, bidRequest.bidderCode),
done: requestCallbacks.done
} : undefined);
adapter.callBids(bidRequest, addBidResponse, done, ajax);
} else {
utils.logError(`Adapter trying to be called which does not exist: ${bidRequest.bidderCode} adaptermanager.callBids`);
}
utils.logMessage(`CALLING BIDDER ======= ${bidRequest.bidderCode}`);
events.emit(CONSTANTS.EVENTS.BID_REQUESTED, bidRequest);
bidRequest.doneCbCallCount = 0;
let done = doneCb(bidRequest.bidderRequestId);
let ajax = ajaxBuilder(clientBidRequests[0].timeout, requestCallbacks ? {
request: requestCallbacks.request.bind(null, bidRequest.bidderCode),
done: requestCallbacks.done
} : undefined);
adapter.callBids(bidRequest, addBidResponse, done, ajax);
});
}

Expand Down
3 changes: 2 additions & 1 deletion test/spec/unit/core/adapterManager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ describe('adapterManager tests', () => {
}];

let bidRequests = AdapterManager.makeBidRequests(adUnits, 1111, 2222, 1000);
AdapterManager.callBids(adUnits, bidRequests, () => {}, () => {});
expect(bidRequests.length).to.equal(1);
expect(bidRequests[0].bidderCode).to.equal('appnexus');
sinon.assert.called(utils.logError);
});

Expand Down

0 comments on commit 6637c7b

Please sign in to comment.