From 9b7f0dfffb19de25f644de1993e751797cd2f6b5 Mon Sep 17 00:00:00 2001 From: jsnellbaker <31102355+jsnellbaker@users.noreply.github.com> Date: Wed, 20 Jun 2018 16:17:32 -0400 Subject: [PATCH] update consentManagement error logic/handling (#2723) --- modules/consentManagement.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/modules/consentManagement.js b/modules/consentManagement.js index af668523fa4c..fcaeab815440 100644 --- a/modules/consentManagement.js +++ b/modules/consentManagement.js @@ -219,11 +219,17 @@ export function requestBidsHook(reqBidsConfigObj, fn) { * @param {object} hookConfig contains module related variables (see comment in requestBidsHook function) */ function processCmpData(consentObject, hookConfig) { + let gdprApplies = consentObject && consentObject.getConsentData && consentObject.getConsentData.gdprApplies; if ( - !utils.isPlainObject(consentObject) || - (!utils.isPlainObject(consentObject.getVendorConsents) || Object.keys(consentObject.getVendorConsents).length === 0) || - (!utils.isPlainObject(consentObject.getConsentData) || Object.keys(consentObject.getConsentData).length === 0)) { - cmpFailed(`CMP returned unexpected value during lookup process; returned value was (${consentObject}).`, hookConfig); + (typeof gdprApplies !== 'boolean') || + (gdprApplies === true && + !(utils.isStr(consentObject.getConsentData.consentData) && + utils.isPlainObject(consentObject.getVendorConsents) && + Object.keys(consentObject.getVendorConsents).length > 1 + ) + ) + ) { + cmpFailed(`CMP returned unexpected value during lookup process.`, hookConfig, consentObject); } else { clearTimeout(hookConfig.timer); storeConsentData(consentObject); @@ -243,15 +249,16 @@ function cmpTimedOut(hookConfig) { * This function contains the controlled steps to perform when there's a problem with CMP. * @param {string} errMsg required; should be a short descriptive message for why the failure/issue happened. * @param {object} hookConfig contains module related variables (see comment in requestBidsHook function) + * @param {object} extraArgs contains additional data that's passed along in the error/warning messages for easier debugging */ -function cmpFailed(errMsg, hookConfig) { +function cmpFailed(errMsg, hookConfig, extraArgs) { clearTimeout(hookConfig.timer); // still set the consentData to undefined when there is a problem as per config options if (allowAuction) { storeConsentData(undefined); } - exitModule(errMsg, hookConfig); + exitModule(errMsg, hookConfig, extraArgs); } /** @@ -282,8 +289,9 @@ function storeConsentData(cmpConsentObject) { * 3. bad exit with auction canceled (error message is logged). * @param {string} errMsg optional; only to be used when there was a 'bad' exit. String is a descriptive message for the failure/issue encountered. * @param {object} hookConfig contains module related variables (see comment in requestBidsHook function) + * @param {object} extraArgs contains additional data that's passed along in the error/warning messages for easier debugging */ -function exitModule(errMsg, hookConfig) { +function exitModule(errMsg, hookConfig, extraArgs) { if (hookConfig.haveExited === false) { hookConfig.haveExited = true; @@ -293,10 +301,10 @@ function exitModule(errMsg, hookConfig) { if (errMsg) { if (allowAuction) { - utils.logWarn(errMsg + ' Resuming auction without consent data as per consentManagement config.'); + utils.logWarn(errMsg + ' Resuming auction without consent data as per consentManagement config.', extraArgs); nextFn.apply(context, args); } else { - utils.logError(errMsg + ' Canceling auction as per consentManagement config.'); + utils.logError(errMsg + ' Canceling auction as per consentManagement config.', extraArgs); if (typeof hookConfig.bidsBackHandler === 'function') { hookConfig.bidsBackHandler(); } else {