Merge pull request #837 from bluewave-labs/feat/be/error-handling
Feat/be/error handling
This commit is contained in:
22 files changed
+235
-63
No files matched your search
@@ -11,7 +11,7 @@ const {
|
||||
deleteAlertParamValidation,
|
||||
} = require("../validation/joi");
|
||||
const { successMessages } = require("../utils/messages");
|
||||
const SERVICE_NAME = "alerts";
|
||||
const SERVICE_NAME = "alertController";
|
||||
|
||||
/**
|
||||
* Creates an alert for a monitor
|
||||
@@ -41,7 +41,8 @@ const createAlert = async (req, res, next) => {
|
||||
.status(200)
|
||||
.json({ success: true, msg: successMessages.ALERT_CREATE, data: alert });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "createAlert") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -100,7 +100,8 @@ const registerController = async (req, res, next) => {
|
||||
data: { user: newUser, token: token },
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "registerController") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -152,7 +153,8 @@ const loginController = async (req, res, next) => {
|
||||
});
|
||||
} catch (error) {
|
||||
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);
|
||||
}
|
||||
};
|
||||
@@ -213,7 +215,8 @@ const userEditController = async (req, res, next) => {
|
||||
data: updatedUser,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "userEditController") : null;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
@@ -259,7 +262,8 @@ const inviteController = async (req, res, next) => {
|
||||
.status(200)
|
||||
.json({ success: true, msg: "Invite sent", data: inviteToken });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "inviteController") : null;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
@@ -283,7 +287,10 @@ const inviteVerifyController = async (req, res, next) => {
|
||||
.status(200)
|
||||
.json({ status: "success", msg: "Invite verified", data: invite });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "inviteVerifyController")
|
||||
: null;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
@@ -306,7 +313,10 @@ const checkSuperadminController = async (req, res) => {
|
||||
data: superAdminExists,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "checkSuperadminController")
|
||||
: null;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
@@ -356,7 +366,10 @@ const recoveryRequestController = async (req, res, next) => {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "recoveryRequestController")
|
||||
: null;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
@@ -391,7 +404,10 @@ const validateRecoveryTokenController = async (req, res, next) => {
|
||||
msg: successMessages.AUTH_VERIFY_RECOVERY_TOKEN,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "validateRecoveryTokenController")
|
||||
: null;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
@@ -427,7 +443,10 @@ const resetPasswordController = async (req, res, next) => {
|
||||
data: { user, token },
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "resetPasswordController")
|
||||
: null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -482,8 +501,8 @@ const deleteUserController = async (req, res, next) => {
|
||||
msg: successMessages.AUTH_DELETE_USER,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method === undefined && error.method === "deleteUserController";
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "deleteUserController") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -495,7 +514,10 @@ const getAllUsersController = async (req, res) => {
|
||||
.status(200)
|
||||
.json({ success: true, msg: "Got all users", data: allUsers });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "getAllUsersController")
|
||||
: null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -60,7 +60,8 @@ const inviteController = async (req, res, next) => {
|
||||
.status(200)
|
||||
.json({ success: true, msg: "Invite sent", data: inviteToken });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "inviteController") : null;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
@@ -84,7 +85,10 @@ const inviteVerifyController = async (req, res, next) => {
|
||||
.status(200)
|
||||
.json({ status: "success", msg: "Invite verified", data: invite });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "inviteVerifyController")
|
||||
: null;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,10 @@ const createMaintenanceWindow = async (req, res, next) => {
|
||||
data: maintenanceWindow,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "createMaintenanceWindow")
|
||||
: null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -68,7 +71,10 @@ const getMaintenanceWindowsByUserId = async (req, res, next) => {
|
||||
data: maintenanceWindows,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "getMaintenanceWindowsByUserId")
|
||||
: null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -98,7 +104,10 @@ const getMaintenanceWindowsByMonitorId = async (req, res, next) => {
|
||||
data: maintenanceWindows,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "getMaintenanceWindowsByMonitorId")
|
||||
: null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -38,7 +38,8 @@ const getAllMonitors = async (req, res, next) => {
|
||||
data: monitors,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "getAllMonitors") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -77,6 +78,10 @@ const getMonitorAggregateStats = async (req, res, next) => {
|
||||
data: aggregateStats,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "getMonitorAggregateStats")
|
||||
: null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -109,7 +114,8 @@ const getMonitorStatsById = async (req, res, next) => {
|
||||
data: monitorStats,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "getMonitorStatsById") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -145,7 +151,10 @@ const getMonitorCertificate = async (req, res, next) => {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "getMonitorCertificate")
|
||||
: null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -184,7 +193,8 @@ const getMonitorById = async (req, res, next) => {
|
||||
data: monitor,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "getMonitorById") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -229,9 +239,10 @@ const getMonitorsAndSummaryByTeamId = async (req, res, next) => {
|
||||
data: monitorsSummary,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method === undefined &&
|
||||
error.method === "getMonitorsAndSummaryByTeamId";
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "getMonitorsAndSummaryByTeamId")
|
||||
: null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -267,7 +278,8 @@ const getMonitorsByTeamId = async (req, res, next) => {
|
||||
data: monitors,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "getMonitorsByTeamId") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -316,7 +328,8 @@ const createMonitor = async (req, res, next) => {
|
||||
data: monitor,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "createMonitor") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -361,14 +374,14 @@ const deleteMonitor = async (req, res, next) => {
|
||||
.status(200)
|
||||
.json({ success: true, msg: successMessages.MONITOR_DELETE });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "deleteMonitor") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteAllMonitors = async (req, res) => {
|
||||
try {
|
||||
console.log("WTF");
|
||||
const token = getTokenFromHeaders(req.headers);
|
||||
const { teamId } = jwt.verify(token, process.env.JWT_SECRET);
|
||||
const { monitors, deletedCount } = await req.db.deleteAllMonitors(teamId);
|
||||
@@ -384,8 +397,8 @@ const deleteAllMonitors = async (req, res) => {
|
||||
.status(200)
|
||||
.json({ success: true, msg: `Deleted ${deletedCount} monitors` });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method === undefined && error.method === "deleteAllMonitors";
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "deleteAllMonitors") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -441,7 +454,8 @@ const editMonitor = async (req, res, next) => {
|
||||
data: editedMonitor,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "editMonitor") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -475,8 +489,8 @@ const pauseMonitor = async (req, res, next) => {
|
||||
data: monitor,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "pauseMonitor";
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "pauseMonitor") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -495,8 +509,8 @@ const addDemoMonitors = async (req, res, next) => {
|
||||
data: demoMonitors.length,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method === undefined && error.method === "addDemoMonitors";
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "addDemoMonitors") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const PageSpeedService = require("../service/pageSpeedService");
|
||||
const { successMessages } = require("../utils/messages");
|
||||
const pageSpeedService = new PageSpeedService();
|
||||
const SERVICE_NAME = "pagespeed";
|
||||
const SERVICE_NAME = "pagespeedCheckController";
|
||||
const {
|
||||
getPageSpeedCheckParamValidation,
|
||||
createPageSpeedCheckParamValidation,
|
||||
@@ -33,7 +33,8 @@ const getPageSpeedChecks = async (req, res, next) => {
|
||||
try {
|
||||
return res.status(200).json({ msg: "Hit getPageSpeedChecks" });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "getPageSpeedChecks") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -86,7 +87,8 @@ const createPageSpeedCheck = async (req, res, next) => {
|
||||
data: newPageSpeedCheck,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "createPageSpeedCheck") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
@@ -114,7 +116,8 @@ const deletePageSpeedCheck = async (req, res, next) => {
|
||||
try {
|
||||
return res.status(200).json({ msg: "Hit deletePageSpeedCheck" });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "deletePageSpeedCheck") : null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const SERVICE_NAME = "JobQueue";
|
||||
const SERVICE_NAME = "JobQueueController";
|
||||
|
||||
const getMetrics = async (req, res, next) => {
|
||||
try {
|
||||
@@ -7,7 +7,8 @@ const getMetrics = async (req, res, next) => {
|
||||
.status(200)
|
||||
.json({ success: true, msg: "Metrics retrieved", data: metrics });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "getMetrics") : null;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
@@ -18,7 +19,8 @@ const getJobs = async (req, res, next) => {
|
||||
const jobs = await req.jobQueue.getJobStats();
|
||||
return res.status(200).json({ jobs });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "getJobs") : null;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
@@ -29,7 +31,8 @@ const addJob = async (req, res, next) => {
|
||||
await req.jobQueue.addJob(Math.random().toString(36).substring(7));
|
||||
return res.send("Added job");
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "addJob") : null;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
@@ -40,7 +43,8 @@ const obliterateQueue = async (req, res, next) => {
|
||||
const obliterated = await req.jobQueue.obliterate();
|
||||
return res.status(200).send("Obliterated jobs");
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "obliterateQueue") : null;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -24,11 +24,8 @@ const dateRangeLookup = {
|
||||
const createCheck = async (checkData) => {
|
||||
try {
|
||||
const { monitorId, status } = checkData;
|
||||
|
||||
const n = (await Check.countDocuments({ monitorId })) + 1;
|
||||
|
||||
const check = await new Check({ ...checkData }).save();
|
||||
|
||||
const monitor = await Monitor.findById(monitorId);
|
||||
|
||||
if (!monitor) {
|
||||
@@ -39,6 +36,7 @@ const createCheck = async (checkData) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update uptime percentage
|
||||
if (monitor.uptimePercentage === undefined) {
|
||||
monitor.uptimePercentage = status === true ? 1 : 0;
|
||||
} else {
|
||||
@@ -50,6 +48,8 @@ const createCheck = async (checkData) => {
|
||||
|
||||
return check;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "createCheck";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -137,6 +137,8 @@ const getChecks = async (req) => {
|
||||
.sort({ createdAt: sortOrder });
|
||||
return checks;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getChecks";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -207,6 +209,8 @@ const deleteChecks = async (monitorId) => {
|
||||
const result = await Check.deleteMany({ monitorId });
|
||||
return result.deletedCount;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "deleteChecks";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -235,6 +239,22 @@ const deleteChecksByTeamId = async (teamId) => {
|
||||
|
||||
return totalDeletedCount;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "deleteChecksByTeamId";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const updateChecksTTL = async (teamId, ttl) => {
|
||||
try {
|
||||
await Check.collection.dropIndex("expiry_1");
|
||||
await Check.collection.createIndex(
|
||||
{ expiry: 1 },
|
||||
{ expireAfterSeconds: ttl } // TTL in seconds, adjust as necessary
|
||||
);
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "updateChecksTTL";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const InviteToken = require("../../../models/InviteToken");
|
||||
const crypto = require("crypto");
|
||||
const { errorMessages } = require("../../../utils/messages");
|
||||
const SERVICE_NAME = "inviteModule";
|
||||
|
||||
/**
|
||||
* Request an invite token for a user.
|
||||
@@ -24,6 +25,8 @@ const requestInviteToken = async (userData) => {
|
||||
await inviteToken.save();
|
||||
return inviteToken;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "requestInviteToken";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -48,6 +51,8 @@ const getInviteToken = async (token) => {
|
||||
}
|
||||
return invite;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getInviteToken";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const MaintenanceWindow = require("../../../models/MaintenanceWindow");
|
||||
const SERVICE_NAME = "maintenanceWindowModule";
|
||||
|
||||
/**
|
||||
* Asynchronously creates a new MaintenanceWindow document and saves it to the database.
|
||||
@@ -38,6 +39,8 @@ const createMaintenanceWindow = async (maintenanceWindowData) => {
|
||||
const result = maintenanceWindow.save();
|
||||
return result;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "createMaintenanceWindow";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -59,6 +62,8 @@ const getMaintenanceWindowsByUserId = async (userId) => {
|
||||
const maintenanceWindows = await MaintenanceWindow.find({ userId: userId });
|
||||
return maintenanceWindows;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getMaintenanceWindowByUserId";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -82,6 +87,8 @@ const getMaintenanceWindowsByMonitorId = async (monitorId) => {
|
||||
});
|
||||
return maintenanceWindows;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getMaintenanceWindowsByMonitorId";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -104,6 +111,8 @@ const deleteMaintenaceWindowById = async (maintenanceWindowId) => {
|
||||
await MaintenanceWindow.findByIdAndDelete(maintenanceWindowId);
|
||||
return maintenanceWindow;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "deleteMaintenaceWindowById";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -125,6 +134,8 @@ const deleteMaintenanceWindowByMonitorId = async (monitorId) => {
|
||||
const result = await MaintenanceWindow.deleteMany({ monitorId: monitorId });
|
||||
return result;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "deleteMaintenanceWindowByMonitorId";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -146,6 +157,8 @@ const deleteMaintenanceWindowByUserId = async (userId) => {
|
||||
const result = await MaintenanceWindow.deleteMany({ userId: userId });
|
||||
return result;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "deleteMaintenanceWindowByUserId";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ const { errorMessages } = require("../../../utils/messages");
|
||||
const Notification = require("../../../models/Notification");
|
||||
const { NormalizeData } = require("../../../utils/dataUtils");
|
||||
const demoMonitors = require("../../../utils/demoMonitors.json");
|
||||
const SERVICE_NAME = "monitorModule";
|
||||
|
||||
/**
|
||||
* Get all monitors
|
||||
@@ -19,6 +20,8 @@ const getAllMonitors = async (req, res) => {
|
||||
const monitors = await Monitor.find();
|
||||
return monitors;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getAllMonitors";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -262,6 +265,7 @@ const getMonitorStatsById = async (req) => {
|
||||
|
||||
return monitorStats;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getMonitorStatsById";
|
||||
throw error;
|
||||
}
|
||||
@@ -289,6 +293,8 @@ const getMonitorById = async (monitorId) => {
|
||||
const monitorWithNotifications = await monitor.save();
|
||||
return monitorWithNotifications;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getMonitorById";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -325,6 +331,7 @@ const getMonitorsAndSummaryByTeamId = async (teamId, type) => {
|
||||
monitorCounts.total = monitors.length;
|
||||
return { monitors, monitorCounts };
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getMonitorsAndSummaryByTeamId";
|
||||
throw error;
|
||||
}
|
||||
@@ -402,6 +409,8 @@ const getMonitorsByTeamId = async (req, res) => {
|
||||
);
|
||||
return { monitors: monitorsWithChecks, monitorCount: monitorsCount };
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getMonitorsByTeamId";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -422,6 +431,8 @@ const createMonitor = async (req, res) => {
|
||||
await monitor.save();
|
||||
return monitor;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "createMonitor";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -443,6 +454,8 @@ const deleteMonitor = async (req, res) => {
|
||||
}
|
||||
return monitor;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "deleteMonitor";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -458,6 +471,8 @@ const deleteAllMonitors = async (teamId) => {
|
||||
|
||||
return { monitors, deletedCount };
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "deleteAllMonitors";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -473,6 +488,8 @@ const deleteMonitorsByUserId = async (userId) => {
|
||||
const result = await Monitor.deleteMany({ userId: userId });
|
||||
return result;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "deleteMonitorsByUserId";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -496,6 +513,7 @@ const editMonitor = async (candidateId, candidateMonitor) => {
|
||||
);
|
||||
return editedMonitor;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "editMonitor";
|
||||
throw error;
|
||||
}
|
||||
@@ -517,6 +535,7 @@ const addDemoMonitors = async (userId, teamId) => {
|
||||
const insertedMonitors = await Monitor.insertMany(demoMonitorsToInsert);
|
||||
return insertedMonitors;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "addDemoMonitors";
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -15,6 +15,8 @@ const createNotification = async (notificationData) => {
|
||||
const notification = await new Notification({ ...notificationData }).save();
|
||||
return notification;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "createNotification";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -30,6 +32,8 @@ const getNotificationsByMonitorId = async (monitorId) => {
|
||||
const notifications = await Notification.find({ monitorId });
|
||||
return notifications;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getNotificationsByMonitorId";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -39,6 +43,8 @@ const deleteNotificationsByMonitorId = async (monitorId) => {
|
||||
const result = await Notification.deleteMany({ monitorId });
|
||||
return result.deletedCount;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "deleteNotificationsByMonitorId";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const PageSpeedCheck = require("../../../models/PageSpeedCheck");
|
||||
|
||||
const SERVICE_NAME = "pageSpeedCheckModule";
|
||||
/**
|
||||
* Create a PageSpeed check for a monitor
|
||||
* @async
|
||||
@@ -19,6 +19,8 @@ const createPageSpeedCheck = async (pageSpeedCheckData) => {
|
||||
}).save();
|
||||
return pageSpeedCheck;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "createPageSpeedCheck";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -36,6 +38,8 @@ const getPageSpeedChecks = async (monitorId) => {
|
||||
const pageSpeedChecks = await PageSpeedCheck.find({ monitorId });
|
||||
return pageSpeedChecks;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getPageSpeedChecks";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -53,6 +57,8 @@ const deletePageSpeedChecksByMonitorId = async (monitorId) => {
|
||||
const result = await PageSpeedCheck.deleteMany({ monitorId });
|
||||
return result.deletedCount;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "deletePageSpeedChecksByMonitorId";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ const { GenerateAvatarImage } = require("../../../utils/imageProcessing");
|
||||
|
||||
const DUPLICATE_KEY_CODE = 11000; // MongoDB error code for duplicate key
|
||||
const { ParseBoolean } = require("../../../utils/utils");
|
||||
SERVICE_NAME = "userModule";
|
||||
|
||||
/**
|
||||
* Insert a User
|
||||
@@ -44,8 +45,10 @@ const insertUser = async (userData, imageFile) => {
|
||||
.select("-profileImage"); // .select() doesn't work with create, need to save then find
|
||||
} catch (error) {
|
||||
if (error.code === DUPLICATE_KEY_CODE) {
|
||||
throw new Error(errorMessages.DB_USER_EXISTS);
|
||||
error.message = errorMessages.DB_USER_EXISTS;
|
||||
}
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "insertUser";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -74,6 +77,8 @@ const getUserByEmail = async (email) => {
|
||||
throw new Error(errorMessages.DB_USER_NOT_FOUND);
|
||||
}
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getUserByEmail";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -123,6 +128,8 @@ const updateUser = async (req, res) => {
|
||||
.select("-profileImage");
|
||||
return updatedUser;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "updateUser";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -143,6 +150,8 @@ const deleteUser = async (userId) => {
|
||||
}
|
||||
return deletedUser;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "deleteUser";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -154,6 +163,8 @@ const getAllUsers = async (req, res) => {
|
||||
.select("-profileImage");
|
||||
return users;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getAllUsers";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -163,6 +174,8 @@ const logoutUser = async (userId) => {
|
||||
await UserModel.updateOne({ _id: userId }, { $unset: { authToken: null } });
|
||||
return true;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "logoutUser";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -43,6 +43,7 @@ const isAllowed = (allowedRoles) => {
|
||||
}
|
||||
} catch (error) {
|
||||
error.status = 401;
|
||||
error.method = "isAllowed";
|
||||
error.service = SERVICE_NAME;
|
||||
next(error);
|
||||
return;
|
||||
|
||||
@@ -28,6 +28,7 @@ const verifyJWT = (req, res, next) => {
|
||||
const error = new Error(errorMessages.INVALID_AUTH_TOKEN); // Instantiate a new Error object for improperly formatted token
|
||||
error.status = 400;
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "verifyJWT";
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ const verifyOwnership = (Model, paramName) => {
|
||||
return;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "verifyOwnership";
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ const verifySuperAdmin = (req, res, next) => {
|
||||
const error = new Error(errorMessages.INVALID_AUTH_TOKEN); // Instantiate a new Error object for improperly formatted token
|
||||
error.status = 400;
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "verifySuperAdmin";
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ const connection = {
|
||||
const JOBS_PER_WORKER = 5;
|
||||
const logger = require("../utils/logger");
|
||||
const { errorMessages, successMessages } = require("../utils/messages");
|
||||
const NetworkService = require("./networkService");
|
||||
const SERVICE_NAME = "JobQueue";
|
||||
|
||||
class JobQueue {
|
||||
@@ -47,6 +46,8 @@ class JobQueue {
|
||||
await queue.scaleWorkers(workerStats);
|
||||
return queue;
|
||||
} catch (error) {
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "createJobQueue") : null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -126,8 +127,10 @@ class JobQueue {
|
||||
const load = jobs.length / this.workers.length;
|
||||
return { jobs, load };
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
errorObject.method === undefined
|
||||
? (error.method = "getWorkerStats")
|
||||
: null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -204,8 +207,8 @@ class JobQueue {
|
||||
const jobs = await this.queue.getRepeatableJobs();
|
||||
return jobs;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "getJobs") : null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -221,8 +224,8 @@ class JobQueue {
|
||||
);
|
||||
return { jobs: ret, workers: this.workers.length };
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "getJobStats") : null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -248,7 +251,8 @@ class JobQueue {
|
||||
const workerStats = await this.getWorkerStats();
|
||||
await this.scaleWorkers(workerStats);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "addJob") : null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -277,6 +281,8 @@ class JobQueue {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "deleteJob") : null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -329,6 +335,8 @@ class JobQueue {
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "obliterate") : null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,10 @@ class NetworkService {
|
||||
} catch (error) {
|
||||
const endTime = Date.now();
|
||||
error.responseTime = endTime - startTime;
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.mheotd === undefined
|
||||
? (error.method = "measureResponseTime")
|
||||
: null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ class PageSpeedService {
|
||||
service: this.SERVICE_NAME,
|
||||
error: error.message,
|
||||
});
|
||||
throw new Error("Failed to run PageSpeed check");
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined ? (error.method = "runPageSpeedCheck") : null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +36,16 @@ class PageSpeedService {
|
||||
* @returns {Promise<PageSpeedCheck>} The created PageSpeedCheck document.
|
||||
*/
|
||||
async createPageSpeedCheck(data) {
|
||||
const newPageSpeedCheck = new PageSpeedCheck(data);
|
||||
return await newPageSpeedCheck.save();
|
||||
try {
|
||||
const newPageSpeedCheck = new PageSpeedCheck(data);
|
||||
return await newPageSpeedCheck.save();
|
||||
} catch (error) {
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "createPageSpeedCheck")
|
||||
: null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user