Skip to content

fix: Handle network errors with proper Error objects#3998

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/network-error-handling
Open

fix: Handle network errors with proper Error objects#3998
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/network-error-handling

Conversation

@sentry

@sentry sentry Bot commented Jun 9, 2026

Copy link
Copy Markdown

Description

This PR addresses the "Error: he" issue (GAZEBO-17ZM) which occurred when rejectNetworkError was called, leading to unhandled exceptions in the UI.

Problem:
Previously, rejectNetworkError would return Promise.reject() with a plain JavaScript object {dev, data, status}. When React Query's useSuspenseQueryV5 rethrew this plain object in a minified production bundle, React would report the error as "Error: he", where "he" was the minified variable name holding the plain object. This resulted in an unhandled exception, as the NetworkErrorBoundary was not designed to catch non-Error objects directly and the outer Sentry ErrorBoundary would capture a cryptic message.

Impact:
This change ensures that all network-related rejections are proper Error objects, providing more meaningful stack traces and error messages (no more "Error: he"). It allows the NetworkErrorBoundary to correctly intercept and display user-friendly messages for network-related issues, preventing unhandled exceptions from crashing the application or reporting unhelpful messages to Sentry.

Code Example

No direct code example is provided, but changes are made in src/shared/api/rejectNetworkError.ts and src/layouts/shared/NetworkErrorBoundary/NetworkErrorBoundary.jsx.

Notable Changes

  1. Introduced a NetworkError class: A new class NetworkError was created in src/shared/api/rejectNetworkError.ts that extends the native Error class. This custom error class now properly carries status and data properties.
  2. Updated rejectNetworkError: The rejectNetworkError function now throws instances of the NetworkError class instead of plain objects. This ensures that any rejection from this utility is always a proper Error object.
  3. Enhanced NetworkErrorBoundary: The NetworkErrorBoundary in src/layouts/shared/NetworkErrorBoundary/NetworkErrorBoundary.jsx was updated to explicitly check if an error is an instanceof NetworkError before attempting to access its status property. This prevents incorrect handling of non-NetworkError objects and ensures that only intended network errors are processed by this boundary.

Screenshots

N/A

Link to Sample Entry

N/A

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Fixes GAZEBO-17ZM

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 338 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
gazebo-production-system 5.87MB 158 bytes (0.0%) ⬆️
gazebo-production-esm 5.96MB 180 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: gazebo-production-system

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index-legacy.*.js 158 bytes 717.02kB 0.02%

Files in assets/index-legacy.*.js:

  • ./src/layouts/shared/NetworkErrorBoundary/NetworkErrorBoundary.jsx → Total Size: 7.9kB

  • ./src/shared/api/rejectNetworkError.ts → Total Size: 1.82kB

view changes for bundle: gazebo-production-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index.*.js 180 bytes 639.59kB 0.03%

Files in assets/index.*.js:

  • ./src/layouts/shared/NetworkErrorBoundary/NetworkErrorBoundary.jsx → Total Size: 7.89kB

  • ./src/shared/api/rejectNetworkError.ts → Total Size: 1.82kB

@codecov-public-qa

Copy link
Copy Markdown

❌ 4 Tests Failed:

Tests completed Failed Passed Skipped
1234 4 1230 0
View the top 3 failed test(s) by shortest run time
src/shared/api/rejectNetworkError.test.ts > rejectNetworkError > when the error is 'Owner Not Activated' > returns a rejected promise
Stack Traces | 0.00139s run time
AssertionError: expected NetworkError: TestQueryOpts - Owner Not A… { …(2) } to strictly equal { …(3) }

- Expected
+ Received

- Object {
-   "data": Object {
-     "detail": "test",
-   },
-   "dev": "TestQueryOpts - Owner Not Activated",
-   "status": 403,
- }
+ [NetworkError: TestQueryOpts - Owner Not Activated]
src/shared/api/rejectNetworkError.test.ts > rejectNetworkError > when the error is 'Not Found Error' > returns a rejected promise
Stack Traces | 0.00202s run time
AssertionError: expected NetworkError: TestQueryOpts - Not Found E… { …(2) } to strictly equal { …(3) }

- Expected
+ Received

- Object {
-   "data": undefined,
-   "dev": "TestQueryOpts - Not Found Error",
-   "status": 404,
- }
+ [NetworkError: TestQueryOpts - Not Found Error]
src/shared/api/rejectNetworkError.test.ts > rejectNetworkError > when the error is 'Parsing Error' > returns a rejected promise
Stack Traces | 0.0115s run time
AssertionError: expected NetworkError: TestQueryOpts - Parsing Err… { …(2) } to strictly equal { …(3) }

- Expected
+ Received

- Object {
-   "data": undefined,
-   "dev": "TestQueryOpts - Parsing Error",
-   "status": 400,
- }
+ [NetworkError: TestQueryOpts - Parsing Error]

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@codecov-releaser

Copy link
Copy Markdown
Collaborator

✅ Deploy preview for gazebo ready!

Previews expire after 1 month automatically.

Storybook

Commit Created Cloud Enterprise
151dfd2 Tue, 09 Jun 2026 01:13:17 GMT Cloud Enterprise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant