Server/project/src/ErrorHandler.ts

30 lines
990 B
TypeScript
Raw Normal View History

import readline from "node:readline";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { AsyncQueue } from "@spt/utils/AsyncQueue";
import { WinstonMainLogger } from "@spt/utils/logging/WinstonMainLogger";
2023-03-03 16:23:46 +01:00
export class ErrorHandler
{
private logger: ILogger;
2023-03-03 16:23:46 +01:00
private readLine: readline.Interface;
constructor()
{
this.logger = new WinstonMainLogger(new AsyncQueue());
2023-11-16 02:35:05 +01:00
this.readLine = readline.createInterface({ input: process.stdin, output: process.stdout });
2023-03-03 16:23:46 +01:00
}
public handleCriticalError(err: Error): void
2023-03-03 16:23:46 +01:00
{
this.logger.error("The application had a critical error and failed to run");
this.logger.error(`Exception produced: ${err.name}`);
2023-03-03 16:23:46 +01:00
if (err.stack)
{
this.logger.error(`\nStacktrace:\n${err.stack}`);
}
this.readLine.question("Press Enter to close the window", (_ans) => this.readLine.close());
this.readLine.on("close", () => process.exit(1));
2023-03-03 16:23:46 +01:00
}
}