- Expand recoverable error codes (ECONNABORTED, ERR_NETWORK) - Add message patterns for 'typeerror: fetch failed' and 'undici' errors - Add isNetworkRelatedError() helper for broad network failure detection - Retry on all network-related errors instead of crashing gateway - Remove unnecessary 'void' from fire-and-forget patterns - Add tests for new error patterns Fixes #3005
44 lines
1.8 KiB
TypeScript
44 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { isRecoverableTelegramNetworkError } from "./network-errors.js";
|
|
|
|
describe("isRecoverableTelegramNetworkError", () => {
|
|
it("detects recoverable error codes", () => {
|
|
const err = Object.assign(new Error("timeout"), { code: "ETIMEDOUT" });
|
|
expect(isRecoverableTelegramNetworkError(err)).toBe(true);
|
|
});
|
|
|
|
it("detects additional recoverable error codes", () => {
|
|
const aborted = Object.assign(new Error("aborted"), { code: "ECONNABORTED" });
|
|
const network = Object.assign(new Error("network"), { code: "ERR_NETWORK" });
|
|
expect(isRecoverableTelegramNetworkError(aborted)).toBe(true);
|
|
expect(isRecoverableTelegramNetworkError(network)).toBe(true);
|
|
});
|
|
|
|
it("detects AbortError names", () => {
|
|
const err = Object.assign(new Error("The operation was aborted"), { name: "AbortError" });
|
|
expect(isRecoverableTelegramNetworkError(err)).toBe(true);
|
|
});
|
|
|
|
it("detects nested causes", () => {
|
|
const cause = Object.assign(new Error("socket hang up"), { code: "ECONNRESET" });
|
|
const err = Object.assign(new TypeError("fetch failed"), { cause });
|
|
expect(isRecoverableTelegramNetworkError(err)).toBe(true);
|
|
});
|
|
|
|
it("detects expanded message patterns", () => {
|
|
expect(isRecoverableTelegramNetworkError(new Error("TypeError: fetch failed"))).toBe(true);
|
|
expect(isRecoverableTelegramNetworkError(new Error("Undici: socket failure"))).toBe(true);
|
|
});
|
|
|
|
it("skips message matches for send context", () => {
|
|
const err = new TypeError("fetch failed");
|
|
expect(isRecoverableTelegramNetworkError(err, { context: "send" })).toBe(false);
|
|
expect(isRecoverableTelegramNetworkError(err, { context: "polling" })).toBe(true);
|
|
});
|
|
|
|
it("returns false for unrelated errors", () => {
|
|
expect(isRecoverableTelegramNetworkError(new Error("invalid token"))).toBe(false);
|
|
});
|
|
});
|