From 209921cc89ff58ed6dc8f48c2dbc3750aaec45ed Mon Sep 17 00:00:00 2001 From: Jaimin Panchal Date: Mon, 16 Oct 2017 17:22:27 -0400 Subject: [PATCH] AppnexusAst adapter: logging error message from endpoint (#1697) * logging error message received from endpoint * removed alias --- modules/appnexusAstBidAdapter.js | 32 ++++++++++++------- .../modules/appnexusAstBidAdapter_spec.js | 12 ++++--- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/modules/appnexusAstBidAdapter.js b/modules/appnexusAstBidAdapter.js index b0997992a0c..78b997b3ef4 100644 --- a/modules/appnexusAstBidAdapter.js +++ b/modules/appnexusAstBidAdapter.js @@ -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; @@ -76,6 +76,7 @@ export const spec = { method: 'POST', url: URL, data: payloadString, + bidderRequest }; }, @@ -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; }, diff --git a/test/spec/modules/appnexusAstBidAdapter_spec.js b/test/spec/modules/appnexusAstBidAdapter_spec.js index f8288819a55..d07ee6df543 100644 --- a/test/spec/modules/appnexusAstBidAdapter_spec.js +++ b/test/spec/modules/appnexusAstBidAdapter_spec.js @@ -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])); }); @@ -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); }); @@ -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'); @@ -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');