From bcf922be4878daa632c4c2ef8a0a074f7e78b4df Mon Sep 17 00:00:00 2001 From: alekswilc <aleks@alekswilc.dev> Date: Sun, 18 Aug 2024 03:04:38 +0200 Subject: [PATCH] test --- src/index.ts | 8 ++++---- src/util/SimrailClient.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index d900def0..629b0a88 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,10 +46,10 @@ import { TrainsModule } from './modules/trains.js'; ApiModule.load(); - process.on('unhandledRejection', (reason, promise) => { - console.error(reason); - console.error(promise); - }) + // process.on('unhandledRejection', (reason, promise) => { + // console.error(reason); + // console.error(promise); + // }) })(); diff --git a/src/util/SimrailClient.ts b/src/util/SimrailClient.ts index b95e10d8..e58fbab5 100644 --- a/src/util/SimrailClient.ts +++ b/src/util/SimrailClient.ts @@ -80,15 +80,15 @@ export class SimrailClient extends EventEmitter { private async update() { - const servers = (await fetch('https://panel.simrail.eu:8084/servers-open').then(x => x.json()) as ApiResponse<Server>) + const servers = (await fetch('https://panel.simrail.eu:8084/servers-open').then(x => x.json().catch(x => ({data: [], result: false}))) as ApiResponse<Server>) .data?.filter(x => x.ServerName.includes('Polski')) ?? []; // no plans to support other servers // TODO: maybe node:worker_threads? // TODO: check performance servers.forEach(async (server) => { - const stations = (await fetch('https://panel.simrail.eu:8084/stations-open?serverCode=' + server.ServerCode).then(x => x.json())) as ApiResponse<Station>; - const trains = (await fetch('https://panel.simrail.eu:8084/trains-open?serverCode=' + server.ServerCode).then(x => x.json())) as ApiResponse<Train>; + const stations = (await fetch('https://panel.simrail.eu:8084/stations-open?serverCode=' + server.ServerCode).then(x => x.json()).catch(() => ({ result: false }))) as ApiResponse<Station>; + const trains = (await fetch('https://panel.simrail.eu:8084/trains-open?serverCode=' + server.ServerCode).then(x => x.json()).catch(() => ({ result: false }))) as ApiResponse<Train>; if (stations.result) { if (!this.stations[server.ServerCode]) this.stations[server.ServerCode] = []; if (!this.stationsOccupied[server.ServerCode]) this.stationsOccupied[server.ServerCode] = {};