@milaboratories/pl-drivers 1.2.23 → 1.2.24

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milaboratories/pl-drivers",
3
- "version": "1.2.23",
3
+ "version": "1.2.24",
4
4
  "description": "Drivers and a low-level clients for log streaming, downloading and uploading files from and to pl",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
@@ -27,8 +27,8 @@
27
27
  "undici": "^6.19.8",
28
28
  "zod": "^3.23.8",
29
29
  "@milaboratories/ts-helpers": "^1.0.27",
30
- "@milaboratories/computable": "^2.1.7",
31
30
  "@milaboratories/pl-client": "^2.4.16",
31
+ "@milaboratories/computable": "^2.1.7",
32
32
  "@milaboratories/pl-tree": "^1.3.13",
33
33
  "@milaboratories/pl-model-common": "^1.3.13"
34
34
  },
@@ -668,7 +668,7 @@ export class Download {
668
668
  // in the directory. It can happen when we forgot to call removeAll
669
669
  // in the previous launch.
670
670
  if (await fileOrDirExists(this.path)) {
671
- content.cancel(`the file already existed`); // we don't need the blob
671
+ await content.cancel(`the file already existed`); // we don't need the blob
672
672
  } else {
673
673
  const fileToWrite = Writable.toWeb(fs.createWriteStream(this.path));
674
674
  await content.pipeTo(fileToWrite);
@@ -1,6 +1,7 @@
1
1
  import { Dispatcher, request } from 'undici';
2
2
  import { Readable } from 'node:stream';
3
3
  import { ReadableStream } from 'node:stream/web';
4
+ import { text } from 'node:stream/consumers';
4
5
 
5
6
  export interface DownloadResponse {
6
7
  content: ReadableStream;
@@ -24,21 +25,25 @@ export class DownloadHelper {
24
25
  signal
25
26
  });
26
27
 
27
- if (400 <= statusCode && statusCode < 500) {
28
- body.on('error', (_) => {}).destroy();
29
- throw new NetworkError400(
30
- `Http error: statusCode: ${statusCode} url: ${url.toString()}`
31
- );
32
- }
28
+ const webBody = Readable.toWeb(body);
29
+
33
30
  if (statusCode != 200) {
34
- body.on('error', (_) => {}).destroy();
31
+ const textBody = await text(webBody)
32
+ const beginning = textBody.substring(0, Math.min(textBody.length, 1000));
33
+
34
+ if (400 <= statusCode && statusCode < 500) {
35
+ throw new NetworkError400(
36
+ `Http error: statusCode: ${statusCode} url: ${url.toString()}, beginning of body: ${beginning}`
37
+ );
38
+ }
39
+
35
40
  throw new Error(
36
41
  `Http error: statusCode: ${statusCode} url: ${url.toString()}`
37
42
  );
38
43
  }
39
44
 
40
45
  return {
41
- content: Readable.toWeb(body),
46
+ content: webBody,
42
47
  size: Number(headers['content-length'])
43
48
  };
44
49
  }