From e3573a9b77fbce78fedff38601a0e8e4c252d946 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Wed, 27 Aug 2025 09:55:19 +0100 Subject: [PATCH] fix: Refactor monitor not found error handling to use centralized exception messages --- Common/Server/Services/MonitorService.ts | 9 +++++---- .../Services/WorkspaceNotificationRuleService.ts | 3 ++- Common/Server/Utils/Monitor/MonitorResource.ts | 3 ++- Common/Types/Exception/ExceptionMessages.ts | 8 ++++++++ .../ProcessIncomingRequestIngest.ts | 16 +++++----------- 5 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 Common/Types/Exception/ExceptionMessages.ts diff --git a/Common/Server/Services/MonitorService.ts b/Common/Server/Services/MonitorService.ts index 93cca4643a..c0ccbd94a5 100644 --- a/Common/Server/Services/MonitorService.ts +++ b/Common/Server/Services/MonitorService.ts @@ -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 { public constructor() { @@ -162,11 +163,11 @@ export class Service extends DatabaseService { }); 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 || ""; diff --git a/Common/Server/Services/WorkspaceNotificationRuleService.ts b/Common/Server/Services/WorkspaceNotificationRuleService.ts index f95d2df698..d3be71595d 100644 --- a/Common/Server/Services/WorkspaceNotificationRuleService.ts +++ b/Common/Server/Services/WorkspaceNotificationRuleService.ts @@ -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 { 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