From 8eb44e18f65d01d2db7a5473791330aaa811a7ec Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 7 Nov 2024 10:12:05 +0100 Subject: [PATCH] fix(server.js): properly propagate errors --- server.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/server.js b/server.js index 2a538e1..c352a0d 100644 --- a/server.js +++ b/server.js @@ -9,7 +9,7 @@ const app = express(); app.use(express.json()); // Determine the merged calendars directory based on the environment -const MERGED_CALENDARS_DIR = path.join(__dirname, 'calendar'); +const MERGED_CALENDARS_DIR = path.join(process.cwd(), 'calendar'); console.log(`Merged calendars directory: ${MERGED_CALENDARS_DIR} under ${process.cwd()}`); // Ensure the merged calendars directory exists @@ -56,10 +56,9 @@ app.post('/merge', async (req, res) => { prefix: calendar.prefix, override: calendar.override, }); - - } catch (error){ - console.error(`Error reading calendar file ${calendar.url}:`, error); - return Promise.resolve(null); + } catch (error) { + console.error(`Error reading calendar file ${calendar.url}: ${error}`); + return Promise.reject(error) } } else { // Fetch calendar data from URL @@ -79,14 +78,11 @@ app.post('/merge', async (req, res) => { }); const results = await Promise.all(promises); - // Filter out any failed requests - const validResults = results.filter((result) => result !== null); - // Create a new iCalendar instance const calendar = icalGenerator({ name: linkGroupName }); // Parse calendar data - validResults.forEach((result) => { + results.forEach((result) => { const parsed = ICAL.parse(result.data); const component = new ICAL.Component(parsed); const events = component.getAllSubcomponents('vevent');