diff --git a/client/src/Hooks/useNotificationForm.ts b/client/src/Hooks/useNotificationForm.ts index 34959dce2..b48d021da 100644 --- a/client/src/Hooks/useNotificationForm.ts +++ b/client/src/Hooks/useNotificationForm.ts @@ -8,27 +8,30 @@ interface UseNotificationFormOptions { export const useNotificationForm = ({ data = null }: UseNotificationFormOptions = {}) => { return useMemo(() => { - const defaults = - data?.type === "matrix" - ? { - type: "matrix" as const, - notificationName: data.notificationName || "", - homeserverUrl: data.homeserverUrl || "", - roomId: data.roomId || "", - accessToken: data.accessToken || "", - } - : data?.type === "telegram" - ? { - type: "telegram" as const, - notificationName: data.notificationName || "", - address: data.address || "", - accessToken: data.accessToken || "", - } - : { - type: (data?.type || "email") as Exclude, - notificationName: data?.notificationName || "", - address: data?.address || "", - }; + let defaults; + + if (data?.type === "matrix") { + defaults = { + type: "matrix" as const, + notificationName: data.notificationName || "", + homeserverUrl: data.homeserverUrl || "", + roomId: data.roomId || "", + accessToken: data.accessToken || "", + }; + } else if (data?.type === "telegram") { + defaults = { + type: "telegram" as const, + notificationName: data.notificationName || "", + address: data.address || "", + accessToken: data.accessToken || "", + }; + } else { + defaults = { + type: (data?.type || "email") as Exclude, + notificationName: data?.notificationName || "", + address: data?.address || "", + }; + } return { schema: notificationSchema, defaults }; }, [data]); diff --git a/server/src/service/infrastructure/notificationProviders/telegram.ts b/server/src/service/infrastructure/notificationProviders/telegram.ts index e6fe8d32a..cd55fd78f 100644 --- a/server/src/service/infrastructure/notificationProviders/telegram.ts +++ b/server/src/service/infrastructure/notificationProviders/telegram.ts @@ -3,7 +3,7 @@ import type { Notification } from "@/types/index.js"; import { INotificationProvider } from "@/service/index.js"; import type { NotificationMessage } from "@/types/notificationMessage.js"; import { getTestMessage } from "@/service/infrastructure/notificationProviders/utils.js"; -import got, { HTTPError } from "got"; +import got from "got"; import { ILogger } from "@/utils/logger.js"; export class TelegramProvider implements INotificationProvider { @@ -28,12 +28,14 @@ export class TelegramProvider implements INotificationProvider { }); return true; } catch (error) { - const err = error as HTTPError; + const errMsg = error instanceof Error ? error.message : "unknown error"; + const errStack = error instanceof Error ? error.stack : undefined; this.logger.warn({ message: "Telegram test alert failed", service: SERVICE_NAME, method: "sendTestAlert", - stack: err?.stack, + stack: errStack, + error: errMsg, }); return false; } @@ -61,12 +63,14 @@ export class TelegramProvider implements INotificationProvider { }); return true; } catch (error) { - const err = error as HTTPError; + const errMsg = error instanceof Error ? error.message : "unknown error"; + const errStack = error instanceof Error ? error.stack : undefined; this.logger.warn({ message: "Telegram alert failed", service: SERVICE_NAME, method: "sendMessage", - stack: err?.stack, + stack: errStack, + error: errMsg, }); return false; }