Add service name and method name to errors in recovery module

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

View File

@@ -1,5 +1,5 @@
const Notification = require("../../../models/Notification");
const SERVICE_NAME = "notificationModule";
/**
* Creates a new notification.
* @param {Object} notificationData - The data for the new notification.

View File

@@ -1,5 +1,5 @@
const PageSpeedCheck = require("../../../models/PageSpeedCheck");
const SERVICE_NAME = "pageSpeedCheckModule";
/**
* Create a PageSpeed check for a monitor
* @async

View File

@@ -2,6 +2,7 @@ const UserModel = require("../../../models/user");
const RecoveryToken = require("../../../models/RecoveryToken");
const crypto = require("crypto");
const { errorMessages } = require("../../../utils/messages");
const SERVICE_NAME = "recoveryModule";
/**
* Request a recovery token
@@ -22,6 +23,8 @@ const requestRecoveryToken = async (req, res) => {
await recoveryToken.save();
return recoveryToken;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "requestRecoveryToken";
throw error;
}
};
@@ -38,6 +41,8 @@ const validateRecoveryToken = async (req, res) => {
throw new Error(errorMessages.DB_TOKEN_NOT_FOUND);
}
} catch (error) {
error.service = SERVICE_NAME;
error.method = "validateRecoveryToken";
throw error;
}
};
@@ -70,6 +75,8 @@ const resetPassword = async (req, res) => {
throw new Error(errorMessages.DB_USER_NOT_FOUND);
}
} catch (error) {
error.service = SERVICE_NAME;
error.method = "resetPassword";
throw error;
}
};