Skip to content

fix(js-sdk): don't return the unchanged request/response from the API logger - #1987

Open
KarlFredrikssonEthira wants to merge 1 commit into
e2b-dev:mainfrom
KarlFredrikssonEthira:fix/js-sdk-api-logger-foreign-response
Open

KarlFredrikssonEthira wants to merge 1 commit into
e2b-dev:mainfrom
KarlFredrikssonEthira:fix/js-sdk-api-logger-foreign-response

Conversation

@KarlFredrikssonEthira

@KarlFredrikssonEthira KarlFredrikssonEthira commented Oct 15, 2026 •

Copy link
Copy Markdown

Fixes #1986.

Problem

On Node, passing a logger makes every API call fail before the response is handled:

Error: onResponse: must return new Response() when modifying the response

On Node, the API client fetches through undici, whose Response is not globalThis.Response. createApiLogger returned the response it received from onResponse. openapi-fetch treats any returned value as a replacement, and requires it to be instanceof 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 onRequest and onResponse hooks in createApiLogger now return nothing, which openapi-fetch reads as "unchanged". The logging itself is the same.

Usage

This now works on Node:

import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create({ logger: console })

Tests

  • New test in tests/logs.test.ts: an openapi-fetch client whose fetch returns an undici Response, with createApiLogger installed. It fails on main with the error above and passes with this change.
  • pnpm run lint and pnpm run format are clean for the changed files.
  • I couldn't run pnpm run typecheck fully: in my partial install, @e2b/dockerfile-utils wasn't built, so it fails in files this change doesn't touch.
  • The Python SDKs don't use openapi-fetch or this middleware, so there is no equivalent change there.

Changeset: e2b patch.

🤖 Generated with Claude Code


Devin Review

… 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>
@cla-bot

cla-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Karl Fredriksson.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@changeset-bot

changeset-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e918f17

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
e2b Patch

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T05:06:33.787728Z e918f17 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TASTE.md review: complies — checked T-1 (parity: Python SDKs do not use openapi-fetch middleware, so no mirror change needed), T-54 (createApiLogger stays internal, not exported from index.ts), T-69/T-70 (no public surface changed); 0 violations.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 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'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@mishushakov

Copy link
Copy Markdown
Member

Hey, please sign the CLA and read the above suggestions.

This branch has not been deployed

No deployments
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.

[Bug]: JS SDK: passing logger makes every API call fail on Node with "onResponse: must return new Response() when modifying the response"

2 participants