From 69a6718af8d078ce9f3e151b408fa7d109bf1ce9 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Sun, 20 Oct 2024 01:27:43 +0300 Subject: [PATCH] update saveCalendarData function --- server.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 01adbb5..82122ca 100644 --- a/server.js +++ b/server.js @@ -114,10 +114,17 @@ app.get('/calendar/:id', (req, res) => { }); //function to save CalendarData to calendars.json -function saveCalendarData(calendarId, calendars) { +function saveCalendarData(calendarId, linkGroupName, calendars) { let calendarsData = { mergedCalendars: [] }; if (fs.existsSync(CALENDARS_FILE)) { - calendarsData = JSON.parse(fs.readFileSync(CALENDARS_FILE, 'utf8')); + try { + const fileContent = fs.readFileSync(CALENDARS_FILE, 'utf8'); + if (fileContent) { + calendarsData = JSON.parse(fileContent); + } + } catch (error) { + console.error('Error reading calendars file:', error); + } } calendarsData.mergedCalendars.push({ id: calendarId,