Use middleware for handling errors.
This commit is contained in:
1 parent
8007daa66b
commit
70ffe1b661
1 file changed
+4
-12
@@ -1,11 +1,10 @@
|
|||||||
import logger from '../utils/logger.js';
|
|
||||||
|
|
||||||
class NotificationController {
|
class NotificationController {
|
||||||
constructor(notificationService) {
|
constructor(notificationService) {
|
||||||
this.notificationService = notificationService;
|
this.notificationService = notificationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
async triggerNotification(req, res) {
|
async triggerNotification(req, res, next) {
|
||||||
try {
|
try {
|
||||||
const { monitorId, type, config } = req.body;
|
const { monitorId, type, config } = req.body;
|
||||||
|
|
||||||
@@ -28,16 +27,9 @@ class NotificationController {
|
|||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error({
|
error.service = "NotificationController";
|
||||||
message: error.message,
|
error.method = "triggerNotification";
|
||||||
service: "NotificationController",
|
next(error);
|
||||||
method: "triggerNotification",
|
|
||||||
stack: error.stack,
|
|
||||||
});
|
|
||||||
|
|
||||||
return res.error({
|
|
||||||
msg: "Failed to send notification"
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user