@rg-dev/stdlib 1.0.15 → 1.0.17

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.
@@ -13,7 +13,7 @@ type MaybeFunction = ((...args: any) => void) | undefined;
13
13
  declare class Optional<T> {
14
14
  private value;
15
15
  private constructor();
16
- static of<T>(val: T): Optional<T>;
16
+ static of<T>(val: T | undefined): Optional<T>;
17
17
  orElseThrow(msg?: string): T;
18
18
  setValue(newValue: T): this;
19
19
  getValue(): T | undefined;
@@ -13,7 +13,7 @@ type MaybeFunction = ((...args: any) => void) | undefined;
13
13
  declare class Optional<T> {
14
14
  private value;
15
15
  private constructor();
16
- static of<T>(val: T): Optional<T>;
16
+ static of<T>(val: T | undefined): Optional<T>;
17
17
  orElseThrow(msg?: string): T;
18
18
  setValue(newValue: T): this;
19
19
  getValue(): T | undefined;
@@ -6071,6 +6071,17 @@ __export(node_download_exports, {
6071
6071
  module.exports = __toCommonJS(node_download_exports);
6072
6072
  var fs2 = __toESM(require("fs"), 1);
6073
6073
  var import_stream = require("stream");
6074
+
6075
+ // src/common-env.ts
6076
+ async function catchInline(cb) {
6077
+ try {
6078
+ return { error: void 0, result: await cb };
6079
+ } catch (e2) {
6080
+ return { error: e2, result: void 0 };
6081
+ }
6082
+ }
6083
+
6084
+ // src/node-download.ts
6074
6085
  async function getFetch() {
6075
6086
  if (typeof fetch !== "undefined") {
6076
6087
  return fetch;
@@ -6084,13 +6095,8 @@ function downloadFile(url, destination, headers) {
6084
6095
  const fetcher = await getFetch();
6085
6096
  const response = await fetcher(url, { headers: { ...headers || {} } });
6086
6097
  if (!response.ok) {
6087
- try {
6088
- const error = await (response == null ? void 0 : response.text());
6089
- if (error)
6090
- throw new Error(error);
6091
- } catch (e2) {
6092
- }
6093
- throw new Error("Error downloading file ");
6098
+ const { result: error } = await catchInline(response.text());
6099
+ throw new Error(`Error throwed while downloading file: ${error || "status code: " + response.status}`);
6094
6100
  }
6095
6101
  const dest = fs2.createWriteStream(destination);
6096
6102
  const body = response.body;
@@ -6072,6 +6072,17 @@ var init_src = __esm({
6072
6072
  // src/node-download.ts
6073
6073
  import * as fs2 from "fs";
6074
6074
  import { Readable } from "stream";
6075
+
6076
+ // src/common-env.ts
6077
+ async function catchInline(cb) {
6078
+ try {
6079
+ return { error: void 0, result: await cb };
6080
+ } catch (e2) {
6081
+ return { error: e2, result: void 0 };
6082
+ }
6083
+ }
6084
+
6085
+ // src/node-download.ts
6075
6086
  async function getFetch() {
6076
6087
  if (typeof fetch !== "undefined") {
6077
6088
  return fetch;
@@ -6085,13 +6096,8 @@ function downloadFile(url, destination, headers) {
6085
6096
  const fetcher = await getFetch();
6086
6097
  const response = await fetcher(url, { headers: { ...headers || {} } });
6087
6098
  if (!response.ok) {
6088
- try {
6089
- const error = await (response == null ? void 0 : response.text());
6090
- if (error)
6091
- throw new Error(error);
6092
- } catch (e2) {
6093
- }
6094
- throw new Error("Error downloading file ");
6099
+ const { result: error } = await catchInline(response.text());
6100
+ throw new Error(`Error throwed while downloading file: ${error || "status code: " + response.status}`);
6095
6101
  }
6096
6102
  const dest = fs2.createWriteStream(destination);
6097
6103
  const body = response.body;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rg-dev/stdlib",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",