mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
refactor: Improve error handling in CheckHeartbeat.ts
This commit improves the error handling in the CheckHeartbeat.ts file. It adds a try-catch block around the main logic to catch any errors that occur during the processing of incoming request monitors. Additionally, it logs the error message and the ID of the monitor that caused the error. This change enhances the robustness and reliability of the code by properly handling and logging errors.
This commit is contained in:
parent
09a7e155b7
commit
9348076df0
@ -41,32 +41,39 @@ RunCron(
|
||||
logger.debug(incomingRequestMonitors);
|
||||
|
||||
for (const monitor of incomingRequestMonitors) {
|
||||
if (!monitor.monitorSteps) {
|
||||
logger.debug("Monitor has no steps. Skipping...");
|
||||
continue;
|
||||
try {
|
||||
if (!monitor.monitorSteps) {
|
||||
logger.debug("Monitor has no steps. Skipping...");
|
||||
continue;
|
||||
}
|
||||
|
||||
const processRequest: boolean = shouldProcessRequest(monitor);
|
||||
|
||||
logger.debug(
|
||||
`Monitor: ${monitor.id} should process request: ${processRequest}`,
|
||||
);
|
||||
|
||||
if (!processRequest) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const incomingRequest: IncomingMonitorRequest = {
|
||||
monitorId: monitor.id!,
|
||||
requestHeaders: undefined,
|
||||
requestBody: undefined,
|
||||
requestMethod: undefined,
|
||||
incomingRequestReceivedAt:
|
||||
monitor.incomingRequestReceivedAt || monitor.createdAt!,
|
||||
onlyCheckForIncomingRequestReceivedAt: true,
|
||||
};
|
||||
|
||||
await ProbeMonitorResponseService.processProbeResponse(incomingRequest);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Error while processing incoming request monitor: ${monitor.id?.toString()}`,
|
||||
);
|
||||
logger.error(error);
|
||||
}
|
||||
|
||||
const processRequest: boolean = shouldProcessRequest(monitor);
|
||||
|
||||
logger.debug(
|
||||
`Monitor: ${monitor.id} should process request: ${processRequest}`,
|
||||
);
|
||||
|
||||
if (!processRequest) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const incomingRequest: IncomingMonitorRequest = {
|
||||
monitorId: monitor.id!,
|
||||
requestHeaders: undefined,
|
||||
requestBody: undefined,
|
||||
requestMethod: undefined,
|
||||
incomingRequestReceivedAt:
|
||||
monitor.incomingRequestReceivedAt || monitor.createdAt!,
|
||||
onlyCheckForIncomingRequestReceivedAt: true,
|
||||
};
|
||||
|
||||
await ProbeMonitorResponseService.processProbeResponse(incomingRequest);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user