mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-01-16 23:00:51 +00:00
fix: Refactor monitor not found error handling to use centralized exception messages
This commit is contained in:
parent
c9e78044e6
commit
e3573a9b77
5 changed files with 22 additions and 17 deletions
|
|
@ -67,6 +67,7 @@ import QueryOperator from "../../Types/BaseDatabase/QueryOperator";
|
|||
import { FindWhere } from "../../Types/BaseDatabase/Query";
|
||||
import logger from "../Utils/Logger";
|
||||
import PushNotificationUtil from "../Utils/PushNotificationUtil";
|
||||
import ExceptionMessages from "../../Types/Exception/ExceptionMessages";
|
||||
|
||||
export class Service extends DatabaseService<Model> {
|
||||
public constructor() {
|
||||
|
|
@ -162,11 +163,11 @@ export class Service extends DatabaseService<Model> {
|
|||
});
|
||||
|
||||
if (!monitor) {
|
||||
throw new BadDataException("Monitor not found.");
|
||||
throw new BadDataException(ExceptionMessages.MonitorNotFound);
|
||||
}
|
||||
|
||||
if (!monitor.id) {
|
||||
throw new BadDataException("Monitor id not found.");
|
||||
throw new BadDataException(ExceptionMessages.MonitorNotFound);
|
||||
}
|
||||
|
||||
projectId = monitor.projectId!;
|
||||
|
|
@ -1389,7 +1390,7 @@ ${createdItem.description?.trim() || "No description provided."}
|
|||
});
|
||||
|
||||
if (!monitor) {
|
||||
throw new BadDataException("Monitor not found.");
|
||||
throw new BadDataException(ExceptionMessages.MonitorNotFound);
|
||||
}
|
||||
|
||||
return (monitor.postUpdatesToWorkspaceChannels || []).filter(
|
||||
|
|
@ -1419,7 +1420,7 @@ ${createdItem.description?.trim() || "No description provided."}
|
|||
});
|
||||
|
||||
if (!monitor) {
|
||||
throw new BadDataException("Monitor not found.");
|
||||
throw new BadDataException(ExceptionMessages.MonitorNotFound);
|
||||
}
|
||||
|
||||
return monitor.name || "";
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import WorkspaceNotificationLog from "../../Models/DatabaseModels/WorkspaceNotif
|
|||
import WorkspaceNotificationLogService from "./WorkspaceNotificationLogService";
|
||||
import WorkspaceNotificationStatus from "../../Types/Workspace/WorkspaceNotificationStatus";
|
||||
import WorkspaceNotificationActionType from "../../Types/Workspace/WorkspaceNotificationActionType";
|
||||
import ExceptionMessages from "../../Types/Exception/ExceptionMessages";
|
||||
|
||||
export interface MessageBlocksByWorkspaceType {
|
||||
workspaceType: WorkspaceType;
|
||||
|
|
@ -1911,7 +1912,7 @@ export class Service extends DatabaseService<WorkspaceNotificationRule> {
|
|||
if (!monitor) {
|
||||
logger.debug("Monitor not found for ID:");
|
||||
logger.debug(data.notificationFor.monitorId);
|
||||
throw new BadDataException("Monitor ID not found");
|
||||
throw new BadDataException(ExceptionMessages.MonitorNotFound);
|
||||
}
|
||||
|
||||
const monitorLabels: Array<Label> = monitor?.labels || [];
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ import CaptureSpan from "../Telemetry/CaptureSpan";
|
|||
import MetricType from "../../../Models/DatabaseModels/MetricType";
|
||||
import MonitorLog from "../../../Models/AnalyticsModels/MonitorLog";
|
||||
import MonitorLogService from "../../Services/MonitorLogService";
|
||||
import ExceptionMessages from "../../../Types/Exception/ExceptionMessages";
|
||||
|
||||
export default class MonitorResourceUtil {
|
||||
@CaptureSpan()
|
||||
|
|
@ -109,7 +110,7 @@ export default class MonitorResourceUtil {
|
|||
|
||||
if (!monitor) {
|
||||
logger.debug(`${dataToProcess.monitorId.toString()} Monitor not found`);
|
||||
throw new BadDataException("Monitor not found");
|
||||
throw new BadDataException(ExceptionMessages.MonitorNotFound);
|
||||
}
|
||||
|
||||
if (!monitor.projectId) {
|
||||
|
|
|
|||
8
Common/Types/Exception/ExceptionMessages.ts
Normal file
8
Common/Types/Exception/ExceptionMessages.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
|
||||
enum ExceptionMessages{
|
||||
MonitorNotFound= "Monitor not found."
|
||||
};
|
||||
|
||||
|
||||
export default ExceptionMessages;
|
||||
|
|
@ -31,17 +31,11 @@ QueueWorker.getWorker(
|
|||
`Successfully processed incoming request ingestion job: ${job.name}`,
|
||||
);
|
||||
} catch (error) {
|
||||
// If monitor is disabled (maintenance / manual incident / explicitly disabled),
|
||||
// we don't want to treat this as a failed job because the ingestion attempt
|
||||
// has effectively "succeeded" (there's nothing actionable to do) and retrying
|
||||
// only creates noise in the failed jobs list.
|
||||
const message: string = (error as Error)?.message || "";
|
||||
if (
|
||||
error instanceof BadDataException && message &&
|
||||
message.toString().toLowerCase().includes("monitor is disabled")
|
||||
) {
|
||||
// Swallow error so BullMQ marks job as completed.
|
||||
return;
|
||||
// Certain BadDataException cases are expected / non-actionable and should not fail the job.
|
||||
// These include disabled monitors (manual, maintenance, explicitly disabled) and missing monitors
|
||||
// (e.g. secret key referencing a deleted monitor). Retrying provides no value and only creates noise.
|
||||
if (error instanceof BadDataException){
|
||||
|
||||
}
|
||||
|
||||
logger.error(`Error processing incoming request ingestion job:`);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue