Add service name and method name to errors in authController

This commit is contained in:
Alex Holliday committed 2024-09-15 09:25:35 +08:00
1 parent cb80ea122f
commit be0db003ad
2 files changed
+37 -14

No files matched your search

+3 -2
View File
@@ -11,7 +11,7 @@ const {
deleteAlertParamValidation, deleteAlertParamValidation,
} = require("../validation/joi"); } = require("../validation/joi");
const { successMessages } = require("../utils/messages"); const { successMessages } = require("../utils/messages");
const SERVICE_NAME = "alerts"; const SERVICE_NAME = "alertController";
/** /**
* Creates an alert for a monitor * Creates an alert for a monitor
@@ -41,7 +41,8 @@ const createAlert = async (req, res, next) => {
.status(200) .status(200)
.json({ success: true, msg: successMessages.ALERT_CREATE, data: alert }); .json({ success: true, msg: successMessages.ALERT_CREATE, data: alert });
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined ? (error.method = "createAlert") : null;
next(error); next(error);
} }
}; };
+34 -12
View File
@@ -100,7 +100,8 @@ const registerController = async (req, res, next) => {
data: { user: newUser, token: token }, data: { user: newUser, token: token },
}); });
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined ? (error.method = "registerController") : null;
next(error); next(error);
} }
}; };
@@ -152,7 +153,8 @@ const loginController = async (req, res, next) => {
}); });
} catch (error) { } catch (error) {
error.status = 500; error.status = 500;
// Anything else should be an error error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined ? (error.method = "loginController") : null;
next(error); next(error);
} }
}; };
@@ -213,7 +215,8 @@ const userEditController = async (req, res, next) => {
data: updatedUser, data: updatedUser,
}); });
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined ? (error.method = "userEditController") : null;
next(error); next(error);
return; return;
} }
@@ -259,7 +262,8 @@ const inviteController = async (req, res, next) => {
.status(200) .status(200)
.json({ success: true, msg: "Invite sent", data: inviteToken }); .json({ success: true, msg: "Invite sent", data: inviteToken });
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined ? (error.method = "inviteController") : null;
next(error); next(error);
return; return;
} }
@@ -283,7 +287,10 @@ const inviteVerifyController = async (req, res, next) => {
.status(200) .status(200)
.json({ status: "success", msg: "Invite verified", data: invite }); .json({ status: "success", msg: "Invite verified", data: invite });
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined
? (error.method = "inviteVerifyController")
: null;
next(error); next(error);
return; return;
} }
@@ -306,7 +313,10 @@ const checkSuperadminController = async (req, res) => {
data: superAdminExists, data: superAdminExists,
}); });
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined
? (error.method = "checkSuperadminController")
: null;
next(error); next(error);
return; return;
} }
@@ -356,7 +366,10 @@ const recoveryRequestController = async (req, res, next) => {
}); });
} }
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined
? (error.method = "recoveryRequestController")
: null;
next(error); next(error);
return; return;
} }
@@ -391,7 +404,10 @@ const validateRecoveryTokenController = async (req, res, next) => {
msg: successMessages.AUTH_VERIFY_RECOVERY_TOKEN, msg: successMessages.AUTH_VERIFY_RECOVERY_TOKEN,
}); });
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined
? (error.method = "validateRecoveryTokenController")
: null;
next(error); next(error);
return; return;
} }
@@ -427,7 +443,10 @@ const resetPasswordController = async (req, res, next) => {
data: { user, token }, data: { user, token },
}); });
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined
? (error.method = "resetPasswordController")
: null;
next(error); next(error);
} }
}; };
@@ -482,8 +501,8 @@ const deleteUserController = async (req, res, next) => {
msg: successMessages.AUTH_DELETE_USER, msg: successMessages.AUTH_DELETE_USER,
}); });
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined && error.method === "deleteUserController"; error.method === undefined ? (error.method = "deleteUserController") : null;
next(error); next(error);
} }
}; };
@@ -495,7 +514,10 @@ const getAllUsersController = async (req, res) => {
.status(200) .status(200)
.json({ success: true, msg: "Got all users", data: allUsers }); .json({ success: true, msg: "Got all users", data: allUsers });
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined
? (error.method = "getAllUsersController")
: null;
next(error); next(error);
} }
}; };