Server/project/src/ErrorHandler.ts

33 lines
1.1 KiB
TypeScript
Raw Normal View History

import readline from "node:readline";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { AsyncQueue } from "@spt-aki/utils/AsyncQueue";
import { UUidGenerator } from "@spt-aki/utils/UUidGenerator";
import { WinstonMainLogger } from "@spt-aki/utils/logging/WinstonMainLogger";
2023-03-03 15:23:46 +00:00
export class ErrorHandler
{
private logger: ILogger;
2023-03-03 15:23:46 +00:00
private readLine: readline.Interface;
constructor()
{
this.logger = new WinstonMainLogger(new AsyncQueue(), new UUidGenerator());
this.readLine = readline.createInterface({ input: process.stdin, output: process.stdout });
2023-03-03 15:23:46 +00:00
}
public handleCriticalError(err: any): void
{
this.logger.error("The application had a critical error and failed to run");
this.logger.error(`Exception produced: ${err}`);
if (err.stack)
{
2023-03-03 15:23:46 +00:00
this.logger.error(`\nStacktrace:\n ${err.stack}`);
}
2023-03-03 15:23:46 +00:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.readLine.question("Press Enter to close the window", (_ans) => this.readLine.close());
this.readLine.on("close", () => process.exit(0));
}
}