From 3be0c65109db6760084736241fc75670ab35adcf Mon Sep 17 00:00:00 2001 From: neon_arch Date: Mon, 19 Jun 2023 19:38:45 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20use=20ternary=20condition?= =?UTF-8?q?=20statement=20and=20add=20error-handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/static/cookies.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/public/static/cookies.js b/public/static/cookies.js index 23238e5..90cfe3b 100644 --- a/public/static/cookies.js +++ b/public/static/cookies.js @@ -1,16 +1,17 @@ // This function is executed when any page on the website finsihes loading and -// this function retrieves the cookies if it is present on the user's machine. -// If it is available then the saved cookies is display in the cookies tab +// this function retrieves the cookies if it is present on the user's machine. +// If it is available then the saved cookies is display in the cookies tab // otherwise an appropriate message is displayed if it is not available. document.addEventListener( 'DOMContentLoaded', () => { - let cookie = decodeURIComponent(document.cookie) - if (cookie !== '') { - document.querySelector('.cookies input').value = cookie - } else { + try { + let cookie = decodeURIComponent(document.cookie) document.querySelector('.cookies input').value = - 'No cookies has been saved on your system' + cookie !== '' ? cookie : 'No cookies have been saved on your system' + } catch (error) { + console.error('Error decoding cookie:', error) + document.querySelector('.cookies input').value = 'Error decoding cookie' } }, false