mirror of
https://github.com/fabrice404/olympics-calendar.git
synced 2026-02-25 03:27:08 +00:00
Fix critical bugs: null checks and error handling
Co-authored-by: fabrice404 <12575390+fabrice404@users.noreply.github.com>
This commit is contained in:
@@ -49,7 +49,7 @@ export class ICSGenerator {
|
||||
for (const lang of this.calendar.languages) {
|
||||
const pathSportKey = sportKey || "all-sports";
|
||||
let pathCalendar = "calendar";
|
||||
if (type != "all-events") {
|
||||
if (type !== "all-events") {
|
||||
pathCalendar = type;
|
||||
} else if (nocKey) {
|
||||
pathCalendar = nocKey;
|
||||
@@ -150,7 +150,14 @@ export class ICSGenerator {
|
||||
flag: getFlag(team?.key || ""),
|
||||
};
|
||||
}
|
||||
const competitor = this.calendar.competitors.find(comp => comp.code === competitorId)!;
|
||||
const competitor = this.calendar.competitors.find(comp => comp.code === competitorId);
|
||||
if (!competitor) {
|
||||
return {
|
||||
noc: "",
|
||||
name: competitorId,
|
||||
flag: "🏳️",
|
||||
};
|
||||
}
|
||||
return {
|
||||
noc: competitor.noc,
|
||||
name: competitor.name,
|
||||
|
||||
@@ -4,10 +4,14 @@ import nodeCron from "node-cron";
|
||||
import { Scraper } from "./scraper";
|
||||
|
||||
const main = () => {
|
||||
nodeCron.schedule("*/10 * * * *", () => {
|
||||
removeSync("./cache/schedules");
|
||||
const scraper = new Scraper();
|
||||
scraper.scrape();
|
||||
nodeCron.schedule("*/10 * * * *", async () => {
|
||||
try {
|
||||
removeSync("./cache/schedules");
|
||||
const scraper = new Scraper();
|
||||
await scraper.scrape();
|
||||
} catch (error) {
|
||||
console.error("Error during scheduled scrape:", error);
|
||||
}
|
||||
});
|
||||
|
||||
nodeCron.schedule("0 0 * * *", () => {
|
||||
@@ -16,7 +20,9 @@ const main = () => {
|
||||
});
|
||||
|
||||
const scraper = new Scraper();
|
||||
scraper.scrape();
|
||||
scraper.scrape().catch((error) => {
|
||||
console.error("Error during initial scrape:", error);
|
||||
});
|
||||
};
|
||||
|
||||
main();
|
||||
|
||||
@@ -147,7 +147,9 @@ export class Scraper {
|
||||
|
||||
for (const noc of this.nocs) {
|
||||
const found = data.nocs.find((n) => n.id === noc.key);
|
||||
this.setNoc(found.id, found.name, lang.code);
|
||||
if (found) {
|
||||
this.setNoc(found.id, found.name, lang.code);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user