Skip to content

Commit

Permalink
AppnexusAst adapter: logging error message from endpoint (#1697)
Browse files Browse the repository at this point in the history
* logging error message received from endpoint

* removed alias
  • Loading branch information
jaiminpanchal27 authored and Matt Kendall committed Oct 16, 2017
1 parent 3f8021c commit 209921c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
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

0 comments on commit 209921c

Please sign in to comment.