From c543ab83fbbe2c45a9065f75a80dd347aec79292 Mon Sep 17 00:00:00 2001 From: Ritesh Ghosh Date: Mon, 7 Aug 2023 14:50:18 +0530 Subject: refactor: added `errorHandler` --- src/config/errorHandler.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/config/errorHandler.ts (limited to 'src') diff --git a/src/config/errorHandler.ts b/src/config/errorHandler.ts new file mode 100644 index 0000000..e983f34 --- /dev/null +++ b/src/config/errorHandler.ts @@ -0,0 +1,11 @@ +import { ErrorRequestHandler } from "express"; + +const errorHandler: ErrorRequestHandler = (error, req, res, next) => { + const status = error?.status || 500; + res.status(status).json({ + status, + message: error?.message || "Something Went Wrong", + }); +}; + +export default errorHandler; -- cgit v1.2.3