Repository navigation
fix(js-sdk): don't return the unchanged request/response from the API logger - #1987
KarlFredrikssonEthira wants to merge 1 commit into
Conversation
… logger On Node the API client fetches through undici, whose Response is not globalThis.Response. openapi-fetch treats any value returned from a middleware hook as a replacement and requires it to be an instance of the global Response, so with a `logger` set every API call threw "onResponse: must return new Response() when modifying the response". Return nothing from the hooks, which openapi-fetch reads as "unchanged". Fixes e2b-dev#1986 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Karl Fredriksson.
|
🦋 Changeset detectedLatest commit: e918f17 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e918f17077
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| @@ -1,5 +1,7 @@ | |||
| import createClient from 'openapi-fetch' | |||
| import { Response as UndiciResponse } from 'undici' | |||
There was a problem hiding this comment.
Keep undici out of the shared browser test
When the browser matrix job runs pnpm test:browser, tests/runtimes/browser/vitest.config.mts includes every tests/**/*.test.ts and excludes tests/undici.test.ts specifically because the undici package is Node-only. This new top-level import therefore makes Vite load undici in Chromium before the test can run, causing the required browser leg (and thus SDK Tests Status) to fail during module setup. Move this regression case into the already excluded Node-only suite or construct a foreign response without statically importing undici.
Useful? React with 👍 / 👎.
|
Hey, please sign the CLA and read the above suggestions. |
Fixes #1986.
Problem
On Node, passing a
loggermakes every API call fail before the response is handled:On Node, the API client fetches through undici, whose
Responseis notglobalThis.Response.createApiLoggerreturned the response it received fromonResponse. openapi-fetch treats any returned value as a replacement, and requires it to beinstanceof Response(the global class), so it throws. Under Bun and in browsers the SDK uses the global fetch, so it doesn't happen there.Fix
The
onRequestandonResponsehooks increateApiLoggernow return nothing, which openapi-fetch reads as "unchanged". The logging itself is the same.Usage
This now works on Node:
Tests
tests/logs.test.ts: an openapi-fetch client whose fetch returns an undiciResponse, withcreateApiLoggerinstalled. It fails onmainwith the error above and passes with this change.pnpm run lintandpnpm run formatare clean for the changed files.pnpm run typecheckfully: in my partial install,@e2b/dockerfile-utilswasn't built, so it fails in files this change doesn't touch.Changeset:
e2bpatch.🤖 Generated with Claude Code