Skip to content

fix(http): partial response upon stream abort#6936

Closed
theo-sim-dev wants to merge 6 commits intoaxios:v1.xfrom
theo-sim-dev:fix/error-partial-response-stream-abort
Closed

fix(http): partial response upon stream abort#6936
theo-sim-dev wants to merge 6 commits intoaxios:v1.xfrom
theo-sim-dev:fix/error-partial-response-stream-abort

Conversation

@theo-sim-dev
Copy link
Copy Markdown

@theo-sim-dev theo-sim-dev commented Jun 8, 2025

Fixes #6935

Context

When a stream emits the 'aborted' event after headers are received, the response object becomes inaccessible, leading to a missing err.response. This change ensures that key response data, including the body content received so far, is captured early and included in the resulting error object for better error handling and debugging.

Fix Summary

  • Tracks response metadata (status, statusText, headers, req) and incoming data chunks once headers are received.
  • Constructs a partialResponse (with body as data) and attaches it via AxiosError.from(...) inside responseStream.on('aborted') and req.on('error') (if headers were already received)

Testing

  • Added new unit test: 'should expose partial response on aborted stream', which confirms that err.response includes status, headers, and partial data

Suggestions & Questions

This appears to be the first implementation in Axios that manually preserves and surfaces partial response data for error scenarios where the original response object is inaccessible. I'd appreciate any input on the overall design.

  • It's currently capturing status, statusText, headers, req, and data. Would there be more fields to capture?
  • Would it be valuable to add a isPartial: true flag in the error response object to denote that the response is incomplete?

@theo-sim-dev theo-sim-dev force-pushed the fix/error-partial-response-stream-abort branch from 12b5abb to 47911b7 Compare June 8, 2025 20:10
@theo-sim-dev theo-sim-dev force-pushed the fix/error-partial-response-stream-abort branch from 47911b7 to 118790e Compare June 8, 2025 20:11
Comment thread lib/adapters/http.js
headers: undefined,
req: undefined,
chunks: [],
}

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (97% of all statements in
the enclosing function
have an explicit semicolon).
@jasonsaayman
Copy link
Copy Markdown
Member

Closing in favour of #10708

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.

AxiosError.response is undefined when HTTP stream is aborted after headers are received (Node.js)

3 participants