Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update consentManagement error logic/handling #2723

Merged
merged 1 commit into from
Jun 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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