Skip to content

Commit

Permalink
update consentManagement error logic/handling (prebid#2723)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnellbaker authored and StefanWallin committed Sep 28, 2018
1 parent 6b0e1f5 commit 9b7f0df
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;

Expand All @@ -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 {
Expand Down

0 comments on commit 9b7f0df

Please sign in to comment.