-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Detail Bug Report
Summary
- Context:
isNetworkErroris a validator used byEventQueueto determine if a failed network request should be retried. - Bug: The function only recognizes
TypeErrorobjects and misses network errors reported asDOMException, such asTimeoutErrorandNetworkError. - Actual vs. expected: It returns
falseforTimeoutErrorandNetworkErrorDOMExceptionobjects, whereas it should returntrueas these represent retryable network failures. - Impact: Transient timeouts and other
DOMException-based network errors are not retried, leading to lost analytics events and decreased reliability of the SDK.
Code with Bug
00003| const isError = (value: any) => objectToString.call(value) === "[object Error]"; // <-- BUG 🔴 [Does not match [object DOMException]]
...
00016| export function isNetworkError(error: any) {
00017| const isValid =
00018| error &&
00019| isError(error) &&
00020| error.name === "TypeError" && // <-- BUG 🔴 [Restricts to TypeError, missing TimeoutError and NetworkError]
00021| typeof error.message === "string";Explanation
- Modern
fetchimplementations can throw timeout/network failures asDOMException(e.g.,AbortSignal.timeout()throws aTimeoutErrorDOMException). - The helper
isErrorrejectsDOMExceptionbecauseObject.prototype.toStringreturns"[object DOMException]", so the validator short-circuits and returnsfalse. - Even if the
isErrorcheck is relaxed,isNetworkErrorcurrently requireserror.name === "TypeError", so retryableDOMExceptionnames likeTimeoutErrorandNetworkErrorstill won’t be treated as network errors.
Recommended Fix
- Accept both
[object Error]and[object DOMException]inisError. - Treat
TimeoutErrorandNetworkErroras retryable by expanding thenameallowlist. - Add the common timeout message to the
errorMessagesset.
const isError = (value: any) => {
const tag = objectToString.call(value);
return tag === "[object Error]" || tag === "[object DOMException]"; // <-- FIX 🟢
};
// Add to errorMessages
"The operation was aborted due to timeout", // Node 18+, Chrome
// Update isNetworkError
error &&
isError(error) &&
(error.name === "TypeError" ||
error.name === "TimeoutError" ||
error.name === "NetworkError"); // <-- FIX 🟢History
This bug was introduced in commit a774609. This commit replaced the external is-network-error dependency with a custom internal implementation as part of a major SDK refactor. The new implementation introduced overly restrictive checks that strictly required the error to be a TypeError and match [object Error], failing to account for DOMException types used by modern fetch implementations for timeouts and network failures.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels