Add service name and method name to errors in recovery module

This commit is contained in:
Alex Holliday committed 2024-09-15 09:18:13 +08:00
1 parent b4fd895ea2
commit ba85a563bf
3 files changed
+9 -2

No files matched your search

@@ -1,5 +1,5 @@
const Notification = require("../../../models/Notification"); const Notification = require("../../../models/Notification");
const SERVICE_NAME = "notificationModule";
/** /**
* Creates a new notification. * Creates a new notification.
* @param {Object} notificationData - The data for the new notification. * @param {Object} notificationData - The data for the new notification.
@@ -1,5 +1,5 @@
const PageSpeedCheck = require("../../../models/PageSpeedCheck"); const PageSpeedCheck = require("../../../models/PageSpeedCheck");
const SERVICE_NAME = "pageSpeedCheckModule";
/** /**
* Create a PageSpeed check for a monitor * Create a PageSpeed check for a monitor
* @async * @async
@@ -2,6 +2,7 @@ const UserModel = require("../../../models/user");
const RecoveryToken = require("../../../models/RecoveryToken"); const RecoveryToken = require("../../../models/RecoveryToken");
const crypto = require("crypto"); const crypto = require("crypto");
const { errorMessages } = require("../../../utils/messages"); const { errorMessages } = require("../../../utils/messages");
const SERVICE_NAME = "recoveryModule";
/** /**
* Request a recovery token * Request a recovery token
@@ -22,6 +23,8 @@ const requestRecoveryToken = async (req, res) => {
await recoveryToken.save(); await recoveryToken.save();
return recoveryToken; return recoveryToken;
} catch (error) { } catch (error) {
error.service = SERVICE_NAME;
error.method = "requestRecoveryToken";
throw error; throw error;
} }
}; };
@@ -38,6 +41,8 @@ const validateRecoveryToken = async (req, res) => {
throw new Error(errorMessages.DB_TOKEN_NOT_FOUND); throw new Error(errorMessages.DB_TOKEN_NOT_FOUND);
} }
} catch (error) { } catch (error) {
error.service = SERVICE_NAME;
error.method = "validateRecoveryToken";
throw error; throw error;
} }
}; };
@@ -70,6 +75,8 @@ const resetPassword = async (req, res) => {
throw new Error(errorMessages.DB_USER_NOT_FOUND); throw new Error(errorMessages.DB_USER_NOT_FOUND);
} }
} catch (error) { } catch (error) {
error.service = SERVICE_NAME;
error.method = "resetPassword";
throw error; throw error;
} }
}; };