fix: carry the API error body of a failed streaming request - #1055
Open
vdusek wants to merge 3 commits into
Open
fix: carry the API error body of a failed streaming request#1055vdusek wants to merge 3 commits into
vdusek wants to merge 3 commits into
Conversation
Contributor
|
See more at https://github.com/apify/apify-client-js/actions/runs/34492190815#summary-102921472000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1041.
A failed request with
responseType: 'stream'(LogClient.stream(),getRecord({ stream: true })) handed an unreadIncomingMessagetoApifyApiError.JSON.stringifythrew on its circular references, so the message readUnexpected error: [object Object]and the API'stype,messageanddatawere lost.HttpClientnow reads a streamed error body into a buffer before building the error, as the Python client does, usingconcatStreamToBufferfrom@apify/utilities. A read that fails mid-body is swallowed: a raw socket error carries no status code, which would breakgetRecord({ stream: true })resolving toundefinedon a 404.ApifyApiErrordecodes the buffer once and keeps a non-JSON body as text, so an HTML error page from a proxy is readable instead of a dump of byte values. That last part also improvesdownloadItems()andgetRecord({ buffer: true })errors.Known limitation, left as a follow-up: the body read sits outside the axios timeout, because axios settles a stream response at its headers. The agent's socket idle timeout bounds it, measured at 2043 ms under a 2 s client timeout, and
maxContentLength: -1leaves it without a size cap. Tightening either needs a separate error-body budget.Closes #1043
✍️ Drafted by Claude Code