Skip to content

fix(api): Prevent ZodError on GraphQL error-only 200 responses - #4128

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

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

Conversation

@sentry

@sentry sentry Bot commented Sep 16, 2026

Copy link
Copy Markdown

Description

This PR addresses a ZodError that occurred when the GraphQL API returned an HTTP 200 OK status, but the response body contained only an errors array and no data field. This is a valid GraphQL error response format.

Previously, the graphql() function in src/shared/api/api.ts would resolve the promise with this raw response body if res.ok was true. Consequently, consuming hooks like useOwner would receive an object where res?.data was undefined, leading to a ZodError when attempting to parse undefined as an object.

The fix modifies the graphql() function to explicitly reject the promise when res.ok is true, but the GraphQL response body contains errors and lacks a data field. This ensures that GraphQL errors are propagated as rejections, preventing undefined values from reaching Zod validation and eliminating the ZodError.

Code Example

The changes are primarily within the graphql() function in src/shared/api/api.ts.

Notable Changes

Modified the graphql() function to explicitly reject the promise when the HTTP status is 200 OK but the GraphQL response body contains an errors array and no data field. This ensures proper error propagation for GraphQL errors.

Screenshots

Link to Sample Entry

Legal Boilerplate

Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness 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 Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.

Fixes GAZEBO-1878

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
5754 1 5753 3
View the top 1 failed test(s) by shortest run time
src/pages/AccountSettings/tabs/YAML/YAML.test.jsx > YAMLTab > The api fails > The save button becomes unsaved changes and an error is displayed
Stack Traces | 1.05s run time
TestingLibraryElementError: Unable to find an element with the text: /Something went wrong/. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

Ignored nodes: comments, script, style
<body
  class=""
>
  <div />
</body>

Ignored nodes: comments, script, style
<body
  class=""
>
  <div />
</body>
 ❯ waitForWrapper node_modules/@.../dom/dist/wait-for.js:163:27
 ❯ node_modules/@.../dom/dist/query-helpers.js:86:33
 ❯ .../tabs/YAML/YAML.test.jsx:225:47

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-public-qa

codecov-public-qa Bot commented Sep 16, 2026

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
5754 1 5753 3
View the top 1 failed test(s) by shortest run time
src/pages/AccountSettings/tabs/YAML/YAML.test.jsx > YAMLTab > The api fails > The save button becomes unsaved changes and an error is displayed
Stack Traces | 1.05s run time
TestingLibraryElementError: Unable to find an element with the text: /Something went wrong/. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

Ignored nodes: comments, script, style
<body
  class=""
>
  <div />
</body>

Ignored nodes: comments, script, style
<body
  class=""
>
  <div />
</body>waitForWrapper node_modules/@.../dom/dist/wait-for.js:163:27node_modules/@.../dom/dist/query-helpers.js:86:33
 ❯ .../tabs/YAML/YAML.test.jsx:225:47

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

@sentry

sentry Bot commented Sep 16, 2026

Copy link
Copy Markdown
Author

⚠️ Seer needs additional GitHub permissions

Seer wants to keep iterating on this pull request to get CI passing, but the Sentry GitHub App installation is missing permissions it needs to read the failing checks and push a fix.

Review and accept the updated permissions to let Seer continue: https://github.com/organizations/codecov/settings/installations/86101127/permissions/update

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Bundle Report

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

Detailed changes
Bundle name Size Change
gazebo-production-esm 5.89MB 57 bytes (0.0%) ⬆️
gazebo-production-system 5.82MB 57 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: gazebo-production-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index.*.js 57 bytes 577.87kB 0.01%

Files in assets/index.*.js:

  • ./src/shared/api/api.ts → Total Size: 2.46kB
view changes for bundle: gazebo-production-system

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index-legacy.*.js 57 bytes 657.88kB 0.01%

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

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

@codecov-releaser

Copy link
Copy Markdown
Collaborator

✅ Deploy preview for gazebo ready!

Previews expire after 1 month automatically.

Storybook

Commit Created Cloud Enterprise
3ba1ca0 Wed, 16 Sep 2026 19:21: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