From e873dcf3a8a45d125602843129e66b5eb92f5e0a Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Wed, 9 Oct 2024 14:35:16 -0400 Subject: [PATCH] Fix error messages crashing page --- .../notificationAdd/notificationAdd.jsx | 2 +- server/notifications.model.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/client/admin/notificationUtils/notificationAdd/notificationAdd.jsx b/client/admin/notificationUtils/notificationAdd/notificationAdd.jsx index fd443b30f..5a8ebf5d0 100644 --- a/client/admin/notificationUtils/notificationAdd/notificationAdd.jsx +++ b/client/admin/notificationUtils/notificationAdd/notificationAdd.jsx @@ -53,7 +53,7 @@ const NotificationAdd = ()=>{ setNotificationResult('Notification successfully created.'); setSearching(false); } catch (err) { - console.log(error.response.body.message); + console.log(err.response.body.message); setError(`Error saving notification: ${err.response.body.message}`); setSearching(false); } diff --git a/server/notifications.model.js b/server/notifications.model.js index 578bc01e4..c9adceebb 100644 --- a/server/notifications.model.js +++ b/server/notifications.model.js @@ -27,7 +27,7 @@ NotificationSchema.statics.addNotification = async function(data) { const savedNotification = await newNotification.save(); return savedNotification; } catch (err) { - return { message: err.message || 'Error saving notification' }; + throw { message: err.message || 'Error saving notification' }; } }; @@ -37,20 +37,20 @@ NotificationSchema.statics.deleteNotification = async function(dismissKey) { try { const deletedNotification = await this.findOneAndDelete({ dismissKey }).exec(); if(!deletedNotification) { - return { message: 'Notification not found' }; + throw { message: 'Notification not found' }; } - return { message: 'Notification deleted successfully' }; + return deletedNotification; } catch (err) { - return { message: err.message || 'Error deleting notification' }; + throw { message: err.message || 'Error deleting notification' }; } }; NotificationSchema.statics.getAll = async function() { try { const notifications = await this.find().exec(); - return { notifications }; + return notifications; } catch (err) { - return { message: err.message || 'Error retrieving notifications' }; + throw { message: err.message || 'Error retrieving notifications' }; } };