From 06e3ef305f140f9522bd3d502ae51f4176484089 Mon Sep 17 00:00:00 2001 From: LukasDeco Date: Mon, 19 Aug 2024 10:36:18 -0600 Subject: [PATCH] fix: no rethrowing error telegram --- packages/indexer/src/adapters/telegram-bot.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/indexer/src/adapters/telegram-bot.ts b/packages/indexer/src/adapters/telegram-bot.ts index 07a4ea08..af64e82b 100644 --- a/packages/indexer/src/adapters/telegram-bot.ts +++ b/packages/indexer/src/adapters/telegram-bot.ts @@ -22,7 +22,7 @@ export class TelegramBotAPI implements AlertChatBotInterface { method: "GET" | "POST", endpoint: string, params?: object - ): Promise> { + ): Promise | null> { let response: AxiosResponse>; try { if (method === "GET") { @@ -32,11 +32,14 @@ export class TelegramBotAPI implements AlertChatBotInterface { } return response.data; } catch (error) { - throw new Error(`Failed to make request: ${error}`); + console.error( + `Failed to make request: ${error}. Method: ${method}. Endpoint: ${endpoint}` + ); + return null; } } - public async getMe(): Promise> { + public async getMe(): Promise | null> { return this.request("GET", "getMe"); } @@ -58,7 +61,7 @@ export class TelegramBotAPI implements AlertChatBotInterface { limit?: number, timeout?: number, allowed_updates?: string[] - ): Promise> { + ): Promise | null> { const params = { offset, limit, timeout, allowed_updates }; return this.request("GET", "getUpdates", params); } @@ -74,7 +77,7 @@ type ChatbotApiResponse = { }; export interface AlertChatBotInterface { - getMe(): Promise>; + getMe(): Promise | null>; sendMessage( chatId: number | string, text: string @@ -84,5 +87,5 @@ export interface AlertChatBotInterface { limit?: number, timeout?: number, allowed_updates?: string[] - ): Promise>; + ): Promise | null>; }