Skip to content

[Hook Execution] cloneResponse option causes "Body has already been consumed" in onError hook #93

@vangelif

Description

@vangelif

File: packages/better-fetch/src/fetch.ts (response cloning logic, PR #78)


Fix: Clone the response body before passing it to any hook or consumer. The pattern should be: const cloned = response.clone(); const body = await cloned.json() hand cloned to hooks and let the original stream flow to the caller. Never read from the same stream twice. Merge or incorporate the fix from PR #78 and add a test that enables cloneResponse then reads the body inside onError.


This issue was identified by an agentic audit tool. If this doesn't apply to your project, feel free to close it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions