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

AppnexusAst adapter: logging error message from endpoint #1697

Merged
merged 2 commits into from
Oct 16, 2017
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
32 changes: 21 additions & 11 deletions modules/appnexusAstBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const spec = {
* @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server.
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(bidRequests) {
buildRequests: function(bidRequests, bidderRequest) {
const tags = bidRequests.map(bidToTag);
const userObjBid = bidRequests.find(hasUserInfo);
let userObj;
Expand Down Expand Up @@ -76,6 +76,7 @@ export const spec = {
method: 'POST',
url: URL,
data: payloadString,
bidderRequest
};
},

Expand All @@ -85,18 +86,27 @@ export const spec = {
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse) {
interpretResponse: function(serverResponse, {bidderRequest}) {
const bids = [];
serverResponse.tags.forEach(serverBid => {
const rtbBid = getRtbBid(serverBid);
if (rtbBid) {
if (rtbBid.cpm !== 0 && SUPPORTED_AD_TYPES.includes(rtbBid.ad_type)) {
const bid = newBid(serverBid, rtbBid);
bid.mediaType = parseMediaType(rtbBid);
bids.push(bid);
if (!serverResponse || serverResponse.error) {
let errorMessage = `in response for ${bidderRequest.bidderCode} adapter`;
if (serverResponse && serverResponse.error) { errorMessage += `: ${serverResponse.error}`; }
utils.logError(errorMessage);
return bids;
}

if (serverResponse.tags) {
serverResponse.tags.forEach(serverBid => {
const rtbBid = getRtbBid(serverBid);
if (rtbBid) {
if (rtbBid.cpm !== 0 && SUPPORTED_AD_TYPES.includes(rtbBid.ad_type)) {
const bid = newBid(serverBid, rtbBid);
bid.mediaType = parseMediaType(rtbBid);
bids.push(bid);
}
}
}
});
});
}
return bids;
},

Expand Down
12 changes: 8 additions & 4 deletions test/spec/modules/appnexusAstBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ describe('AppNexusAdapter', () => {
'mediaType': 'banner'
}
];
let bidderRequest;

let result = spec.interpretResponse(response);
let result = spec.interpretResponse(response, {bidderRequest});
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
});

Expand All @@ -319,8 +320,9 @@ describe('AppNexusAdapter', () => {
'nobid': true
}]
};
let bidderRequest;

let result = spec.interpretResponse(response);
let result = spec.interpretResponse(response, {bidderRequest});
expect(result.length).to.equal(0);
});

Expand All @@ -339,8 +341,9 @@ describe('AppNexusAdapter', () => {
}]
}]
};
let bidderRequest;

let result = spec.interpretResponse(response);
let result = spec.interpretResponse(response, {bidderRequest});
expect(result[0]).to.have.property('vastUrl');
expect(result[0]).to.have.property('descriptionUrl');
expect(result[0]).to.have.property('mediaType', 'video');
Expand Down Expand Up @@ -371,8 +374,9 @@ describe('AppNexusAdapter', () => {
},
'impression_trackers': ['http://example.com'],
};
let bidderRequest;

let result = spec.interpretResponse(response1);
let result = spec.interpretResponse(response1, {bidderRequest});
expect(result[0].native.title).to.equal('Native Creative');
expect(result[0].native.body).to.equal('Cool description great stuff');
expect(result[0].native.cta).to.equal('Do it');
Expand Down