From b410e7d7198ba30bd3ec892e0b7a5fd646b03503 Mon Sep 17 00:00:00 2001 From: Dariusz Szut Date: Fri, 22 Nov 2024 12:04:12 +0100 Subject: [PATCH] move try/catch --- .../public/js/scripts/core/storage.js | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/bundle/Resources/public/js/scripts/core/storage.js b/src/bundle/Resources/public/js/scripts/core/storage.js index f13fd8652a..6709b1f5c2 100644 --- a/src/bundle/Resources/public/js/scripts/core/storage.js +++ b/src/bundle/Resources/public/js/scripts/core/storage.js @@ -7,26 +7,8 @@ this.eventName = config.eventName; } - stringifyData(data) { - try { - return JSON.stringify(data); - } catch (error) { - console.warn('Error stringifying data', error); - } - } - - parseData(data) { - try { - return JSON.parse(data); - } catch (error) { - console.warn('Error parsing data', error); - - return null; - } - } - setItem(data) { - const stringifiedData = this.stringifyData(data); + const stringifiedData = JSON.stringify(data); global.localStorage.setItem(this.key, stringifiedData); @@ -34,14 +16,14 @@ } getItem() { - return this.parseData(global.localStorage.getItem(this.key)); + return JSON.parse(global.localStorage.getItem(this.key)); } fireStorageChangeEvent(data) { if (this.eventName) { const storageChangeEvent = new CustomEvent(this.eventName, { cancelable: true, - detail: { content: this.parseData(data) }, + detail: { content: JSON.parse(data) }, }); doc.body.dispatchEvent(storageChangeEvent);