cookieconsent
cookieconsent copied to clipboard
[Feat]: Better handling when translations are undefined
Description
Hello,
so i had this bug in my code, when my function didn't return object with traslations for ConsentModal. Which led to state._currentTranslation.consentModal
be undefined and function createConsentModal
did not create any html elements. This led to unrelated errors about missing dom elements. CookieConsent was trying add events and attributes even, when props like dom._cm
where undefined.
Proposed solution
In createConsentModal
should be atleast console.warn
or throw?
const createConsentModal = (api, createMainContainer) => {
// ...
/**
* @type {import("../global").ConsentModalOptions}
*/
const consentModalData = state._currentTranslation && state._currentTranslation.consentModal;
if (!consentModalData) {
// console.warn('consentModalData is undefined');
// throw new Error('consentModalData is undefined');
return;
}
// ...
Additional details
No response