move errors to fit in logger.error
This commit is contained in:
parent
447dca754b
commit
9295f90741
4 changed files with 16 additions and 9 deletions
|
@ -130,7 +130,7 @@ class Logger {
|
|||
}
|
||||
|
||||
public error(
|
||||
message: string | string[] | Error | Error[],
|
||||
message: string | Error | (string | Error)[],
|
||||
breakLine: boolean = false,
|
||||
): void {
|
||||
const stack: string = new Error().stack || "";
|
||||
|
@ -183,6 +183,10 @@ class Logger {
|
|||
this.writeConsoleMessageColored(logMessageParts, breakLine);
|
||||
}
|
||||
|
||||
public space(): void {
|
||||
console.log();
|
||||
}
|
||||
|
||||
private writeConsoleMessageColored(
|
||||
logMessageParts: ILogMessageParts,
|
||||
breakLine: boolean = false,
|
||||
|
|
|
@ -11,7 +11,6 @@ async function main(): Promise<void> {
|
|||
}
|
||||
|
||||
main().catch((error: Error) => {
|
||||
logger.error("Error initializing the server:");
|
||||
logger.error(error as Error);
|
||||
logger.error(["Error initializing the server:", error]);
|
||||
process.exit(1);
|
||||
});
|
||||
|
|
|
@ -83,8 +83,10 @@ class ServerHandler {
|
|||
return new Response("Not Found", { status: 404 });
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`Error serving static file: ${pathname}`);
|
||||
logger.error(error as Error);
|
||||
logger.error([
|
||||
`Error serving static file: ${pathname}`,
|
||||
error as Error,
|
||||
]);
|
||||
return new Response("Internal Server Error", { status: 500 });
|
||||
}
|
||||
}
|
||||
|
@ -179,8 +181,10 @@ class ServerHandler {
|
|||
}
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
logger.error(`Error handling route ${request.url}:`);
|
||||
logger.error(error as Error);
|
||||
logger.error([
|
||||
`Error handling route ${request.url}:`,
|
||||
error as Error,
|
||||
]);
|
||||
|
||||
response = Response.json(
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@ class WebSocketHandler {
|
|||
try {
|
||||
ws.send(`You said: ${message}`);
|
||||
} catch (error) {
|
||||
logger.error(`WebSocket send error: ${(error as Error).message}`);
|
||||
logger.error(["WebSocket send error", error as Error]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class WebSocketHandler {
|
|||
try {
|
||||
ws.send("Welcome to the WebSocket server!");
|
||||
} catch (error) {
|
||||
logger.error(`WebSocket send error: ${(error as Error).message}`);
|
||||
logger.error(["WebSocket send error", error as Error]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue