diff --git a/modules/id5IdSystem.js b/modules/id5IdSystem.js index 1d55450239b..151782791af 100644 --- a/modules/id5IdSystem.js +++ b/modules/id5IdSystem.js @@ -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}; } diff --git a/modules/identityLinkIdSystem.js b/modules/identityLinkIdSystem.js index 47d8ad9ac05..a7114c2a147 100644 --- a/modules/identityLinkIdSystem.js +++ b/modules/identityLinkIdSystem.js @@ -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); diff --git a/modules/liveIntentIdSystem.js b/modules/liveIntentIdSystem.js index 3f5d0602166..b0e8cfc1c0f 100644 --- a/modules/liveIntentIdSystem.js +++ b/modules/liveIntentIdSystem.js @@ -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}; } diff --git a/modules/parrableIdSystem.js b/modules/parrableIdSystem.js index ba5fae81952..8c487c783ae 100644 --- a/modules/parrableIdSystem.js +++ b/modules/parrableIdSystem.js @@ -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 }; diff --git a/modules/unifiedIdSystem.js b/modules/unifiedIdSystem.js index 9995a260c26..f916030d643 100644 --- a/modules/unifiedIdSystem.js +++ b/modules/unifiedIdSystem.js @@ -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}; } diff --git a/test/spec/modules/liveIntentIdSystem_spec.js b/test/spec/modules/liveIntentIdSystem_spec.js index c3c9c8dc38d..85e0d30b348 100644 --- a/test/spec/modules/liveIntentIdSystem_spec.js +++ b/test/spec/modules/liveIntentIdSystem_spec.js @@ -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); diff --git a/test/spec/modules/parrableIdSystem_spec.js b/test/spec/modules/parrableIdSystem_spec.js index 662f63f6638..0183a6f79d4 100644 --- a/test/spec/modules/parrableIdSystem_spec.js +++ b/test/spec/modules/parrableIdSystem_spec.js @@ -110,6 +110,7 @@ describe('Parrable ID System', function() { describe('Parrable ID in Bid Request', function() { let adUnits; + let logErrorStub; beforeEach(function() { adUnits = [getAdUnitMock()]; @@ -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) { @@ -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; + }); }); });