Handle fetch failed message as transient network error
This commit is contained in:
parent
4583f88626
commit
93be40c397
@ -81,6 +81,11 @@ describe("isTransientNetworkError", () => {
|
||||
expect(isTransientNetworkError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for Error with "TypeError: fetch failed" message', () => {
|
||||
const error = new Error("TypeError: fetch failed");
|
||||
expect(isTransientNetworkError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it("returns true for fetch failed with network cause", () => {
|
||||
const cause = Object.assign(new Error("getaddrinfo ENOTFOUND"), { code: "ENOTFOUND" });
|
||||
const error = Object.assign(new TypeError("fetch failed"), { cause });
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import process from "node:process";
|
||||
|
||||
import { extractErrorCode, formatUncaughtError } from "./errors.js";
|
||||
import { extractErrorCode, formatErrorMessage, formatUncaughtError } from "./errors.js";
|
||||
|
||||
type UnhandledRejectionHandler = (reason: unknown) => boolean;
|
||||
|
||||
@ -88,6 +88,14 @@ export function isTransientNetworkError(err: unknown): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Some environments wrap fetch failures as generic Errors (e.g., "TypeError: fetch failed")
|
||||
const message = formatErrorMessage(err).toLowerCase();
|
||||
if (message.includes("fetch failed")) {
|
||||
const cause = getErrorCause(err);
|
||||
if (cause) return isTransientNetworkError(cause);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check the cause chain recursively
|
||||
const cause = getErrorCause(err);
|
||||
if (cause && cause !== err) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user