Skip to content

improve(errors): accept Responses, type extractResponseBody - #3441

Draft
Dave Shoup (shouples) wants to merge 2 commits into
mainfrom
djs/issue-2683-extract-response-body-generic
Draft

improve(errors): accept Responses, type extractResponseBody#3441
Dave Shoup (shouples) wants to merge 2 commits into
mainfrom
djs/issue-2683-extract-response-body-generic

Conversation

@shouples

Copy link
Copy Markdown
Contributor

Summary of Changes

extractResponseBody() (in src/errors.ts) decodes the body of a failed HTTP response as JSON, falling back to raw text. It only accepted the ResponseError types our generated OpenAPI clients throw, and returned Promise<any> - so every caller got an untyped blob and had to guess at its shape.

Now it also accepts a raw Response, so a direct fetch() call (not through a generated client) can reuse the same decode logic. And it returns a generic Promise<T> (default unknown) instead of any, so each caller passes the body shape it expects (e.g. extractResponseBody<{ message?: string }>(error)) and gets a checked result back.

No runtime behavior change - same decoding, and non-Response/non-ResponseError input still throws (message now mentions both accepted types). Updated the five call sites to pass an explicit type argument, and added unit tests in src/errors.test.ts covering both input kinds across the JSON, text-fallback, and throw paths.

Closes #2683

Optional: Any additional details or context that should be provided?

This is a type-level refactor with no user-visible behavior change, so there's nothing to click-test. Run npx gulp test -t "extractResponseBody" to see the new coverage.

Call sites updated (each now declares the body shape it reads):

  • src/commands/flinkStatements.ts
  • src/commands/medusaCodeLens.ts
  • src/commands/utils/uploadArtifactOrUDF.ts
  • src/flinkSql/flinkStatementResultsManager.ts
  • src/viewProviders/flinkDatabase.ts

Pull request checklist

Please check if your PR fulfills the following (if applicable):

Tests

  • Added new
  • Updated existing
  • Deleted existing

Release notes

  • Does anything in this PR need to be mentioned in the user-facing CHANGELOG? No - internal type-safety refactor with no user-facing change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 24, 2026 15:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors extractResponseBody() to be reusable for both OpenAPI-client ResponseErrors and raw Response objects, while improving type-safety by removing any and pushing callers to declare the response shape they expect.

Changes:

  • Update extractResponseBody() to accept AnyResponseError | Response and return Promise<T> (default unknown), decoding JSON with a text fallback.
  • Update five call sites to provide explicit type arguments when decoding error response bodies.
  • Add unit tests covering both ResponseError and raw Response inputs across JSON, text-fallback, and throw paths.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/errors.ts Generalize extractResponseBody() to accept Response and add generic typing.
src/errors.test.ts Expand unit coverage for extractResponseBody() across both accepted input kinds.
src/commands/flinkStatements.ts Pass an explicit type argument when decoding 400 error bodies for statement submission.
src/commands/medusaCodeLens.ts Pass an explicit type argument when decoding Medusa API error bodies.
src/commands/utils/uploadArtifactOrUDF.ts Pass an explicit type argument when decoding upload error bodies and simplify error extraction.
src/flinkSql/flinkStatementResultsManager.ts Pass an explicit type argument when decoding results-fetch error payloads.
src/viewProviders/flinkDatabase.ts Pass an explicit type argument when decoding artifact-load error bodies for display.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/commands/flinkStatements.ts Outdated
Comment thread src/errors.ts
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sonarqube-confluent

Copy link
Copy Markdown

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.

Update extractResponseBody() to accept Responses and use generic type instead of any

2 participants