From 70ffe1b6614396c944c05f7d27ca30d8d9e737e4 Mon Sep 17 00:00:00 2001 From: Skorpios Date: Wed, 12 Feb 2025 21:17:31 -0800 Subject: [PATCH] Use middleware for handling errors. --- Server/controllers/notificationController.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Server/controllers/notificationController.js b/Server/controllers/notificationController.js index e202c5274..6a19c3a1b 100644 --- a/Server/controllers/notificationController.js +++ b/Server/controllers/notificationController.js @@ -1,11 +1,10 @@ -import logger from '../utils/logger.js'; class NotificationController { constructor(notificationService) { this.notificationService = notificationService; } - async triggerNotification(req, res) { + async triggerNotification(req, res, next) { try { const { monitorId, type, config } = req.body; @@ -28,16 +27,9 @@ class NotificationController { }); } catch (error) { - logger.error({ - message: error.message, - service: "NotificationController", - method: "triggerNotification", - stack: error.stack, - }); - - return res.error({ - msg: "Failed to send notification" - }); + error.service = "NotificationController"; + error.method = "triggerNotification"; + next(error); } } }