From 58b58424abbf98feec0c5442a59f4d055bbd1811 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Sun, 23 Mar 2025 10:06:34 -0500 Subject: [PATCH] test(returnres): tryed to make a standard return res but will come back to this later --- server/globalUtils/routeDefs/returnRes.ts | 29 +++++++++++++++++++++++ server/index.ts | 3 ++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 server/globalUtils/routeDefs/returnRes.ts diff --git a/server/globalUtils/routeDefs/returnRes.ts b/server/globalUtils/routeDefs/returnRes.ts new file mode 100644 index 0000000..deece3f --- /dev/null +++ b/server/globalUtils/routeDefs/returnRes.ts @@ -0,0 +1,29 @@ +import type { Context } from "hono"; + +export type ReturnRes = + | { success: true; message: string; data: T } + | { success: false; message: string; error: any }; + +export const returnRes = ( + success: boolean, + message: string, + data: T | null = null +): ReturnRes => { + /** + * just a simple return to reduce the typing and make sure we are always consitant with our returns. + * + * data can be an error as well. + */ + return success + ? { success, message, data: data as T } + : { success, message, error: data ?? "An unknown error occurred" }; +}; + +// export const returnApi = (c:Context,success: boolean, message: string, data?: any, code: number)=>{ +// /** +// * just a simple return to reduce the typing and make sure we are always consitant with our returns. +// * +// * data can be an error as well. +// */ +// return c.json({success, message, data}, code); +// } diff --git a/server/index.ts b/server/index.ts index e018414..87305ba 100644 --- a/server/index.ts +++ b/server/index.ts @@ -6,7 +6,7 @@ import { serveStatic } from "@hono/node-server/serve-static"; import { logger } from "hono/logger"; import { cors } from "hono/cors"; import { createLog } from "./services/logger/logger.js"; - +import { WebSocketServer } from "ws"; // custom routes import scalar from "./services/general/route/scalar.js"; import system from "./services/server/systemServer.js"; @@ -149,6 +149,7 @@ process.on("uncaughtException", async (err) => { process.on("beforeExit", async () => { console.log("Process is about to exit..."); //await closePool(); + process.exit(0); }); const port =