Fix critical bugs: null checks and error handling

Co-authored-by: fabrice404 <12575390+fabrice404@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-06 21:47:39 +00:00
parent 70b0b4e8c7
commit 7b4c983be6
3 changed files with 23 additions and 8 deletions

View File

@@ -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,

View File

@@ -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();

View File

@@ -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);
}
}
}
}