forked from ryanmwangi/CalMerger
fix(server.js): properly propagate errors
This commit is contained in:
parent
6c9fb1139f
commit
8eb44e18f6
12
server.js
12
server.js
|
@ -9,7 +9,7 @@ const app = express();
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
// Determine the merged calendars directory based on the environment
|
// 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()}`);
|
console.log(`Merged calendars directory: ${MERGED_CALENDARS_DIR} under ${process.cwd()}`);
|
||||||
|
|
||||||
// Ensure the merged calendars directory exists
|
// Ensure the merged calendars directory exists
|
||||||
|
@ -56,10 +56,9 @@ app.post('/merge', async (req, res) => {
|
||||||
prefix: calendar.prefix,
|
prefix: calendar.prefix,
|
||||||
override: calendar.override,
|
override: calendar.override,
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error reading calendar file ${calendar.url}:`, error);
|
console.error(`Error reading calendar file ${calendar.url}: ${error}`);
|
||||||
return Promise.resolve(null);
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fetch calendar data from URL
|
// Fetch calendar data from URL
|
||||||
|
@ -79,14 +78,11 @@ app.post('/merge', async (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const results = await Promise.all(promises);
|
const results = await Promise.all(promises);
|
||||||
// Filter out any failed requests
|
|
||||||
const validResults = results.filter((result) => result !== null);
|
|
||||||
|
|
||||||
// Create a new iCalendar instance
|
// Create a new iCalendar instance
|
||||||
const calendar = icalGenerator({ name: linkGroupName });
|
const calendar = icalGenerator({ name: linkGroupName });
|
||||||
|
|
||||||
// Parse calendar data
|
// Parse calendar data
|
||||||
validResults.forEach((result) => {
|
results.forEach((result) => {
|
||||||
const parsed = ICAL.parse(result.data);
|
const parsed = ICAL.parse(result.data);
|
||||||
const component = new ICAL.Component(parsed);
|
const component = new ICAL.Component(parsed);
|
||||||
const events = component.getAllSubcomponents('vevent');
|
const events = component.getAllSubcomponents('vevent');
|
||||||
|
|
Loading…
Reference in New Issue