diff --git a/backend/src/utils.ts b/backend/src/utils.ts new file mode 100644 index 0000000..316e774 --- /dev/null +++ b/backend/src/utils.ts @@ -0,0 +1,13 @@ +import { Request, Response } from 'express'; + +type ControllerFunction = (req: Request, res: Response) => Promise; + +export function catchError(fn: ControllerFunction): ControllerFunction { + return async function (req: Request, res: Response) { + try { + return await fn(req, res); + } catch (error) { + res.status(500).json({ error: error }); + } + }; +}