Merge 93be40c397 into 09be5d45d5
This commit is contained in:
commit
5f557ec05b
@ -81,6 +81,11 @@ describe("isTransientNetworkError", () => {
|
|||||||
expect(isTransientNetworkError(error)).toBe(true);
|
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", () => {
|
it("returns true for fetch failed with network cause", () => {
|
||||||
const cause = Object.assign(new Error("getaddrinfo ENOTFOUND"), { code: "ENOTFOUND" });
|
const cause = Object.assign(new Error("getaddrinfo ENOTFOUND"), { code: "ENOTFOUND" });
|
||||||
const error = Object.assign(new TypeError("fetch failed"), { cause });
|
const error = Object.assign(new TypeError("fetch failed"), { cause });
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import process from "node:process";
|
import process from "node:process";
|
||||||
|
|
||||||
import { extractErrorCode, formatUncaughtError } from "./errors.js";
|
import { extractErrorCode, formatErrorMessage, formatUncaughtError } from "./errors.js";
|
||||||
|
|
||||||
type UnhandledRejectionHandler = (reason: unknown) => boolean;
|
type UnhandledRejectionHandler = (reason: unknown) => boolean;
|
||||||
|
|
||||||
@ -88,6 +88,14 @@ export function isTransientNetworkError(err: unknown): boolean {
|
|||||||
return true;
|
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
|
// Check the cause chain recursively
|
||||||
const cause = getErrorCause(err);
|
const cause = getErrorCause(err);
|
||||||
if (cause && cause !== err) {
|
if (cause && cause !== err) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user