Skip to content

Commit

Permalink
fix: no rethrowing error telegram
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasDeco committed Aug 19, 2024
1 parent b4c7d9e commit 06e3ef3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/indexer/src/adapters/telegram-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class TelegramBotAPI implements AlertChatBotInterface {
method: "GET" | "POST",
endpoint: string,
params?: object
): Promise<ChatbotApiResponse<T>> {
): Promise<ChatbotApiResponse<T> | null> {
let response: AxiosResponse<ChatbotApiResponse<T>>;
try {
if (method === "GET") {
Expand All @@ -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<ChatbotApiResponse<any>> {
public async getMe(): Promise<ChatbotApiResponse<any> | null> {
return this.request("GET", "getMe");
}

Expand All @@ -58,7 +61,7 @@ export class TelegramBotAPI implements AlertChatBotInterface {
limit?: number,
timeout?: number,
allowed_updates?: string[]
): Promise<ChatbotApiResponse<any>> {
): Promise<ChatbotApiResponse<any> | null> {
const params = { offset, limit, timeout, allowed_updates };
return this.request("GET", "getUpdates", params);
}
Expand All @@ -74,7 +77,7 @@ type ChatbotApiResponse<T> = {
};

export interface AlertChatBotInterface {
getMe(): Promise<ChatbotApiResponse<any>>;
getMe(): Promise<ChatbotApiResponse<any> | null>;
sendMessage(
chatId: number | string,
text: string
Expand All @@ -84,5 +87,5 @@ export interface AlertChatBotInterface {
limit?: number,
timeout?: number,
allowed_updates?: string[]
): Promise<ChatbotApiResponse<any>>;
): Promise<ChatbotApiResponse<any> | null>;
}

0 comments on commit 06e3ef3

Please sign in to comment.