Skip to content

Commit

Permalink
Use middleware for handling errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Skorpios604 committed Feb 13, 2025
1 parent 8007daa commit 70ffe1b
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions Server/controllers/notificationController.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit 70ffe1b

Please sign in to comment.