Skip to content

Commit 397a20a

Browse files
authored
ortbConverter: accept null responses (prebid#13558)
1 parent e257303 commit 397a20a

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

libraries/ortbConverter/converter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export function ortbConverter<B extends BidderCode>({
189189
return {
190190
toORTB({bidderRequest, bidRequests, context = {}}: {
191191
bidderRequest: BidderRequest<B>,
192-
bidRequests: BidRequest<B>[],
192+
bidRequests?: BidRequest<B>[],
193193
context?: Context
194194
}): ORTBRequest {
195195
bidRequests = bidRequests || bidderRequest.bids;
@@ -220,7 +220,7 @@ export function ortbConverter<B extends BidderCode>({
220220
},
221221
fromORTB({request, response}: {
222222
request: ORTBRequest;
223-
response: ORTBResponse;
223+
response: ORTBResponse | null;
224224
}): AdapterResponse {
225225
const ctx = REQ_CTX.get(request);
226226
if (ctx == null) {
@@ -230,7 +230,7 @@ export function ortbConverter<B extends BidderCode>({
230230
return Object.assign(ctx, {ortbRequest: request}, extraParams);
231231
}
232232
const impsById = Object.fromEntries((request.imp || []).map(imp => [imp.id, imp]));
233-
const bidResponses = (response.seatbid || []).flatMap(seatbid =>
233+
const bidResponses = (response?.seatbid || []).flatMap(seatbid =>
234234
(seatbid.bid || []).map((bid) => {
235235
if (impsById.hasOwnProperty(bid.impid) && ctx.imp.hasOwnProperty(bid.impid)) {
236236
return buildBidResponse(bid, augmentContext(ctx.imp[bid.impid], {imp: impsById[bid.impid], seatbid, ortbResponse: response}));

test/spec/ortbConverter/converter_spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ describe('pbjs-ortb converter', () => {
146146
}).to.throw();
147147
});
148148

149+
Object.entries({
150+
'empty': {},
151+
'null': null
152+
}).forEach(([t, resp]) => {
153+
it(`returns no bids when response is ${t}`, () => {
154+
const converter = makeConverter();
155+
const {bids} = converter.fromORTB({
156+
request: converter.toORTB({bidderRequest: MOCK_BIDDER_REQUEST}),
157+
response: resp
158+
});
159+
expect(bids).to.eql([]);
160+
})
161+
})
162+
149163
it('gives precedence to the bidRequests argument over bidderRequest.bids', () => {
150164
expect(makeConverter().toORTB({bidderRequest: MOCK_BIDDER_REQUEST, bidRequests: [MOCK_BIDDER_REQUEST.bids[0]]})).to.eql({
151165
id: 'req0',

0 commit comments

Comments
 (0)