Skip to content

Commit

Permalink
User id fetch error (prebid#5166)
Browse files Browse the repository at this point in the history
* Update Bidder Code

* LunaMedia Adapater

LunaMedia Adapater

* Updated LunamediaBidAdapter.md test params and valid pub code for testing

* Updating User ID submodules to execute callback onError AJAX

* fix parrable test when IE

* parrable spec all messed up after merge, fixed now

Co-authored-by: Chandra Prakash <chandra.prakash@advangelists.com>
Co-authored-by: trchandraprakash <47793448+trchandraprakash@users.noreply.github.com>
Co-authored-by: rmartinez <Rachael24!>
  • Loading branch information
3 people authored May 18, 2020
1 parent 49d5d46 commit 334cb01
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 46 deletions.
25 changes: 16 additions & 9 deletions modules/id5IdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,24 @@ export const id5IdSubmodule = {
const url = `https://id5-sync.com/g/v1/${configParams.partner}.json?1puid=${storedUserId ? storedUserId.id5id : ''}&gdpr=${hasGdpr}&gdpr_consent=${gdprConsentString}`;

const resp = function (callback) {
ajax(url, response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
const callbacks = {
success: response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
}
}
callback(responseObj);
},
error: error => {
utils.logError(`id5Id: ID fetch encountered an error`, error);
callback();
}
callback(responseObj);
}, undefined, { method: 'GET', withCredentials: true });
};
ajax(url, callbacks, undefined, { method: 'GET', withCredentials: true });
};
return {callback: resp};
}
Expand Down
25 changes: 16 additions & 9 deletions modules/identityLinkIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,24 @@ export const identityLinkSubmodule = {
};
// return envelope from third party endpoint
function getEnvelope(url, callback) {
ajax(url, response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
const callbacks = {
success: response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
}
}
callback(responseObj.envelope);
},
error: error => {
utils.logError(`identityLink: ID fetch encountered an error`, error);
callback();
}
callback(responseObj.envelope);
}, undefined, {method: 'GET', withCredentials: true});
};
ajax(url, callbacks, undefined, {method: 'GET', withCredentials: true});
}

submodule('userId', identityLinkSubmodule);
25 changes: 16 additions & 9 deletions modules/liveIntentIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,24 @@ export const liveIntentIdSubmodule = {
// Don't do the internal ajax call, but use the composed url and fire it via PBJS ajax module
const url = liveConnect.resolutionCallUrl();
const result = function (callback) {
ajax(url, response => {
let responseObj = {};
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
const callbacks = {
success: response => {
let responseObj = {};
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
}
}
callback(responseObj);
},
error: error => {
utils.logError(`${MODULE_NAME}: ID fetch encountered an error: `, error);
callback();
}
callback(responseObj);
}, undefined, { method: 'GET', withCredentials: true });
};
ajax(url, callbacks, undefined, { method: 'GET', withCredentials: true });
};
return {callback: result};
}
Expand Down
26 changes: 16 additions & 10 deletions modules/parrableIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,25 @@ function fetchId(configParams, currentStoredId) {
};

const callback = function (cb) {
const onSuccess = (response) => {
let eid;
if (response) {
try {
let responseObj = JSON.parse(response);
eid = responseObj ? responseObj.eid : undefined;
} catch (error) {
utils.logError(error);
const callbacks = {
success: response => {
let eid;
if (response) {
try {
let responseObj = JSON.parse(response);
eid = responseObj ? responseObj.eid : undefined;
} catch (error) {
utils.logError(error);
}
}
cb(eid);
},
error: error => {
utils.logError(`parrableId: ID fetch encountered an error`, error);
cb();
}
cb(eid);
};
ajax(PARRABLE_URL, onSuccess, searchParams, options);
ajax(PARRABLE_URL, callbacks, searchParams, options);
};

return { callback };
Expand Down
25 changes: 16 additions & 9 deletions modules/unifiedIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,24 @@ export const unifiedIdSubmodule = {
const url = configParams.url || `https://match.adsrvr.org/track/rid?ttd_pid=${configParams.partner}&fmt=json`;

const resp = function (callback) {
ajax(url, response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
const callbacks = {
success: response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
}
}
callback(responseObj);
},
error: error => {
utils.logError(`${MODULE_NAME}: ID fetch encountered an error`, error);
callback();
}
callback(responseObj);
}, undefined, {method: 'GET', withCredentials: true});
};
ajax(url, callbacks, undefined, {method: 'GET', withCredentials: true});
};
return {callback: resp};
}
Expand Down
16 changes: 16 additions & 0 deletions test/spec/modules/liveIntentIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ describe('LiveIntentId', function () {
expect(callBackSpy.calledOnce).to.be.true;
});

it('should log an error and continue to callback if ajax request errors', function () {
getCookieStub.returns(null);
let callBackSpy = sinon.spy();
let submoduleCallback = liveIntentIdSubmodule.getId(defaultConfigParams).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.be.eq('https://idx.liadm.com/idex/prebid/89899');
request.respond(
503,
responseHeader,
'Unavailable'
);
expect(logErrorStub.calledOnce).to.be.true;
expect(callBackSpy.calledOnce).to.be.true;
});

it('should include the LiveConnect identifier when calling the LiveIntent Identity Exchange endpoint', function () {
const oldCookie = 'a-xxxx--123e4567-e89b-12d3-a456-426655440000'
getDataFromLocalStorageStub.withArgs('_li_duid').returns(oldCookie);
Expand Down
18 changes: 18 additions & 0 deletions test/spec/modules/parrableIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('Parrable ID System', function() {

describe('Parrable ID in Bid Request', function() {
let adUnits;
let logErrorStub;

beforeEach(function() {
adUnits = [getAdUnitMock()];
Expand All @@ -122,10 +123,12 @@ describe('Parrable ID System', function() {
setSubmoduleRegistry([parrableIdSubmodule]);
init(config);
config.setConfig(getConfigMock());
logErrorStub = sinon.stub(utils, 'logError');
});

afterEach(function() {
storage.setCookie(P_COOKIE_NAME, '', EXPIRED_COOKIE_DATE);
logErrorStub.restore();
});

it('provides the parrableid in the bid request', function(done) {
Expand All @@ -139,5 +142,20 @@ describe('Parrable ID System', function() {
done();
}, { adUnits });
});

it('should log an error and continue to callback if ajax request errors', function () {
let callBackSpy = sinon.spy();
let submoduleCallback = parrableIdSubmodule.getId({partner: 'prebid'}).callback;
submoduleCallback(callBackSpy);
let request = server.requests[0];
expect(request.url).to.contain('h.parrable.com');
request.respond(
503,
null,
'Unavailable'
);
expect(logErrorStub.calledOnce).to.be.true;
expect(callBackSpy.calledOnce).to.be.true;
});
});
});

0 comments on commit 334cb01

Please sign in to comment.