apify-client 3.0.0-beta.18 → 3.0.0-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import retry from 'async-retry';
2
2
  import axios, { AxiosHeaders } from 'axios';
3
3
  import { APIFY_ENV_VARS } from '@apify/consts';
4
+ import { concatStreamToBuffer } from '@apify/utilities';
4
5
  import { ApifyApiError } from './apify_api_error.js';
5
6
  import { InvalidResponseBodyError, requestInterceptors, responseInterceptors } from './interceptors.js';
6
7
  import { asArray, cast, getVersionData, isNode, isStream } from './utils.js';
@@ -171,6 +172,12 @@ export class HttpClient {
171
172
  });
172
173
  if (this.#isStatusOk(response.status))
173
174
  return response;
175
+ // A failed request with `responseType: 'stream'` carries the API error body in the stream. Read
176
+ // it so that `ApifyApiError` can parse it like any other error body. A body that cannot be read
177
+ // leaves the error without a message, which beats losing the status code to a stream error.
178
+ if (isStream(response.data)) {
179
+ response.data = await concatStreamToBuffer(response.data).catch(() => undefined);
180
+ }
174
181
  }
175
182
  catch (err) {
176
183
  return cast(this.#handleRequestError(err, config, stopTrying));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "3.0.0-beta.18",
3
+ "version": "3.0.0-beta.19",
4
4
  "description": "Apify API client for JavaScript",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"