mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
refactor(telegram): share error_code classification
This commit is contained in:
@@ -123,30 +123,27 @@ export function isSafeToRetrySendError(err: unknown): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true for HTTP 5xx server errors (error may have been processed). */
|
function hasTelegramErrorCode(err: unknown, matches: (code: number) => boolean): boolean {
|
||||||
export function isTelegramServerError(err: unknown): boolean {
|
|
||||||
for (const candidate of collectTelegramErrorCandidates(err)) {
|
for (const candidate of collectTelegramErrorCandidates(err)) {
|
||||||
if (candidate && typeof candidate === "object" && "error_code" in candidate) {
|
if (!candidate || typeof candidate !== "object" || !("error_code" in candidate)) {
|
||||||
const code = (candidate as { error_code: unknown }).error_code;
|
continue;
|
||||||
if (typeof code === "number" && code >= 500) {
|
}
|
||||||
return true;
|
const code = (candidate as { error_code: unknown }).error_code;
|
||||||
}
|
if (typeof code === "number" && matches(code)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns true for HTTP 5xx server errors (error may have been processed). */
|
||||||
|
export function isTelegramServerError(err: unknown): boolean {
|
||||||
|
return hasTelegramErrorCode(err, (code) => code >= 500);
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns true for HTTP 4xx client errors (Telegram explicitly rejected, not applied). */
|
/** Returns true for HTTP 4xx client errors (Telegram explicitly rejected, not applied). */
|
||||||
export function isTelegramClientRejection(err: unknown): boolean {
|
export function isTelegramClientRejection(err: unknown): boolean {
|
||||||
for (const candidate of collectTelegramErrorCandidates(err)) {
|
return hasTelegramErrorCode(err, (code) => code >= 400 && code < 500);
|
||||||
if (candidate && typeof candidate === "object" && "error_code" in candidate) {
|
|
||||||
const code = (candidate as { error_code: unknown }).error_code;
|
|
||||||
if (typeof code === "number" && code >= 400 && code < 500) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isRecoverableTelegramNetworkError(
|
export function isRecoverableTelegramNetworkError(
|
||||||
|
|||||||
Reference in New Issue
Block a user