Merge pull request 'test' (#20) from v2 into main

Reviewed-on: alekswilc/simrail-logs#20
Reviewed-by: Aleksander Wilczyński <aleks@alekswilc.dev>
This commit is contained in:
Aleksander Wilczyński 2024-08-18 03:05:54 +02:00
commit af1f86a74a
Signed by: gitea
GPG Key ID: CECFC30736A3D1C8
2 changed files with 7 additions and 7 deletions

View File

@ -46,10 +46,10 @@ import { TrainsModule } from './modules/trains.js';
ApiModule.load(); ApiModule.load();
process.on('unhandledRejection', (reason, promise) => { // process.on('unhandledRejection', (reason, promise) => {
console.error(reason); // console.error(reason);
console.error(promise); // console.error(promise);
}) // })
})(); })();

View File

@ -80,15 +80,15 @@ export class SimrailClient extends EventEmitter {
private async update() { 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 .data?.filter(x => x.ServerName.includes('Polski')) ?? []; // no plans to support other servers
// TODO: maybe node:worker_threads? // TODO: maybe node:worker_threads?
// TODO: check performance // TODO: check performance
servers.forEach(async (server) => { 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 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())) as ApiResponse<Train>; 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 (stations.result) {
if (!this.stations[server.ServerCode]) this.stations[server.ServerCode] = []; if (!this.stations[server.ServerCode]) this.stations[server.ServerCode] = [];
if (!this.stationsOccupied[server.ServerCode]) this.stationsOccupied[server.ServerCode] = {}; if (!this.stationsOccupied[server.ServerCode]) this.stationsOccupied[server.ServerCode] = {};