Skip to content

Commit

Permalink
refactor(portRouters): add logging to notFoundRouter
Browse files Browse the repository at this point in the history
  • Loading branch information
drazisil committed Oct 10, 2024
1 parent 5f61042 commit e36215c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/gateway/src/portRouters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ServerLogger } from "rusty-motors-shared";
import { getServerLogger, type ServerLogger } from "rusty-motors-shared";
import type { TaggedSocket } from "./socketUtility.js";
type PortRouter = (portRouterArgs: {
taggedSocket: TaggedSocket;
Expand Down Expand Up @@ -33,14 +33,18 @@ export function addPortRouter(port: number, router: PortRouter) {

async function notFoundRouter({
taggedSocket,
log = getServerLogger({
name: "gatewayServer.notFoundRouter",
}),
}: {
taggedSocket: TaggedSocket;
log?: ServerLogger;
}) {
taggedSocket.socket.on("error", (error) => {
console.error(`[${taggedSocket.id}] Socket error: ${error}`);
});
taggedSocket.socket.end();
throw new Error(`No router found for port ${taggedSocket.socket.localPort}`);
log.error(`[${taggedSocket.id}] No router found for port ${taggedSocket.socket.localPort}`);
}
/**
* Retrieves the router function associated with a given port.
Expand Down

0 comments on commit e36215c

Please sign in to comment.