fix: [REV-2608] don't stop page processing on invalid cookie data (#29904)

This commit is contained in:
Phillip Shiu
2022-02-10 17:01:04 -05:00
committed by GitHub
parent a6718f9c86
commit 3a376b3d5f

View File

@@ -28,7 +28,18 @@ export class Currency { // eslint-disable-line import/prefer-default-export
}
getCountry() {
this.countryL10nData = JSON.parse($.cookie('edx-price-l10n'));
try {
this.countryL10nData = JSON.parse($.cookie('edx-price-l10n'));
} catch (e) {
if (e instanceof SyntaxError) {
// If cookie isn't proper JSON, log but continue. This will show the purchase experience
// in a non-local currency but will not prevent the user from interacting with the page.
console.error(e);
console.error("Ignoring malformed 'edx-price-l10n' cookie.");
} else {
throw e;
}
}
if (this.countryL10nData) {
window.analytics.track('edx.bi.user.track_selection.local_currency_cookie_set');
this.setPrice();