From 44135570f52f21fa09f56d678060f082274d0a67 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Wed, 4 Dec 2024 22:34:01 +0700 Subject: [PATCH] Create errorHandler.js --- src/utils/errorHandler.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/utils/errorHandler.js diff --git a/src/utils/errorHandler.js b/src/utils/errorHandler.js new file mode 100644 index 000000000..8d79390cf --- /dev/null +++ b/src/utils/errorHandler.js @@ -0,0 +1,14 @@ +// utils/errorHandler.js + +// Error handling utility +class ErrorHandler { + static handleError(err, req, res) { + console.error(err); + res.status(err.status || 500).json({ + success: false, + message: err.message || 'Internal Server Error', + }); + } +} + +module.exports = ErrorHandler;