mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-28 20:25:03 +00:00
fix: scope telegram polling restart to telegram errors (#43799)
* fix: scope telegram polling restart to telegram errors * fix: make telegram error tagging best-effort * fix: scope telegram polling restart to telegram errors (#43799)
This commit is contained in:
@@ -5,6 +5,8 @@ import {
|
||||
readErrorName,
|
||||
} from "../infra/errors.js";
|
||||
|
||||
const TELEGRAM_NETWORK_ORIGIN = Symbol("openclaw.telegram.network-origin");
|
||||
|
||||
const RECOVERABLE_ERROR_CODES = new Set([
|
||||
"ECONNRESET",
|
||||
"ECONNREFUSED",
|
||||
@@ -101,6 +103,51 @@ function getErrorCode(err: unknown): string | undefined {
|
||||
}
|
||||
|
||||
export type TelegramNetworkErrorContext = "polling" | "send" | "webhook" | "unknown";
|
||||
export type TelegramNetworkErrorOrigin = {
|
||||
method?: string | null;
|
||||
url?: string | null;
|
||||
};
|
||||
|
||||
function normalizeTelegramNetworkMethod(method?: string | null): string | null {
|
||||
const trimmed = method?.trim();
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
return trimmed.toLowerCase();
|
||||
}
|
||||
|
||||
export function tagTelegramNetworkError(err: unknown, origin: TelegramNetworkErrorOrigin): void {
|
||||
if (!err || typeof err !== "object") {
|
||||
return;
|
||||
}
|
||||
Object.defineProperty(err, TELEGRAM_NETWORK_ORIGIN, {
|
||||
value: {
|
||||
method: normalizeTelegramNetworkMethod(origin.method),
|
||||
url: typeof origin.url === "string" && origin.url.trim() ? origin.url : null,
|
||||
} satisfies TelegramNetworkErrorOrigin,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function getTelegramNetworkErrorOrigin(err: unknown): TelegramNetworkErrorOrigin | null {
|
||||
for (const candidate of collectTelegramErrorCandidates(err)) {
|
||||
if (!candidate || typeof candidate !== "object") {
|
||||
continue;
|
||||
}
|
||||
const origin = (candidate as Record<PropertyKey, unknown>)[TELEGRAM_NETWORK_ORIGIN];
|
||||
if (!origin || typeof origin !== "object") {
|
||||
continue;
|
||||
}
|
||||
const method = "method" in origin && typeof origin.method === "string" ? origin.method : null;
|
||||
const url = "url" in origin && typeof origin.url === "string" ? origin.url : null;
|
||||
return { method, url };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function isTelegramPollingNetworkError(err: unknown): boolean {
|
||||
return getTelegramNetworkErrorOrigin(err)?.method === "getupdates";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the error is safe to retry for a non-idempotent Telegram send operation
|
||||
|
||||
Reference in New Issue
Block a user