apify-client 3.0.0-beta.17 → 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.
@@ -70,14 +70,16 @@ export class ApifyApiError extends Error {
70
70
  let type;
71
71
  let responseData = response.data;
72
72
  let errorData;
73
- // Some methods (e.g. downloadItems) set up forceBuffer on request response. If this request failed
74
- // the body buffer needs to parse to get the correct error.
73
+ // A `forceBuffer` request (e.g. `downloadItems()`) and a failed streaming request, whose body `HttpClient`
74
+ // has read into a buffer, both arrive unparsed. Parse the body here to get at the error.
75
75
  if (isBuffer(responseData)) {
76
+ const body = isomorphicBufferToString(response.data, 'utf-8');
76
77
  try {
77
- responseData = JSON.parse(isomorphicBufferToString(response.data, 'utf-8'));
78
+ responseData = JSON.parse(body);
78
79
  }
79
80
  catch {
80
- // This can happen. The data in the response body are malformed.
81
+ // A body that is not JSON at all, such as an HTML error page from a proxy, is kept as text.
82
+ responseData = body;
81
83
  }
82
84
  }
83
85
  if (responseData && responseData.error) {