@gershy/util-http 0.0.9 → 0.0.11

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/cmp/cjs/main.d.ts CHANGED
@@ -19,7 +19,7 @@ export type HttpRes = {
19
19
  headers?: {
20
20
  [key: string]: string | string[];
21
21
  };
22
- body: Json | Buffer;
22
+ body: Json | Uint8Array;
23
23
  };
24
24
  export type HttpArgs<Req extends HttpReq, Res extends HttpRes> = {} & {
25
25
  $req: Req;
package/cmp/cjs/main.js CHANGED
@@ -48,14 +48,15 @@ var main_default = (args, params) => {
48
48
  // Avoid `camelCase` util - want to keep this sovereign
49
49
  body: [Object, Array].some((C) => cl.isCls(reqBody, C)) ? JSON.stringify(reqBody) : reqBody !== null ? `${reqBody}` : null
50
50
  };
51
+ const err = new Error("");
51
52
  const abort = new AbortController();
52
53
  const prm = fetch(url, { ...reqArgs, signal: abort.signal }).then(
53
54
  async (res) => {
54
55
  const resBody = await (async () => {
55
- const t = await res.text();
56
+ const t = await res.bytes();
56
57
  try {
57
- return JSON.parse(t);
58
- } catch (err) {
58
+ return JSON.parse(t[cl.toStr]());
59
+ } catch (err2) {
59
60
  }
60
61
  return t;
61
62
  })();
@@ -68,10 +69,10 @@ var main_default = (args, params) => {
68
69
  if (res.status >= 400) throw Error("http reject")[cl.mod](http);
69
70
  return http;
70
71
  },
71
- (err) => {
72
- while (cl.isCls(err.cause, Error)) err = err.cause;
73
- if (err.code === "ENOTFOUND") return err[cl.fire]({ retry: false });
74
- throw err;
72
+ (cause) => {
73
+ while (cl.isCls(cause.cause, Error)) cause = cause.cause;
74
+ if (cause.code === "ENOTFOUND") return err[cl.fire]({ cause, retry: false });
75
+ return err[cl.fire]({ cause });
75
76
  }
76
77
  );
77
78
  return Object.assign(prm, { end: () => abort.abort(Error("fetch aborted")[cl.suppress]()) });
package/cmp/esm/main.d.ts CHANGED
@@ -19,7 +19,7 @@ export type HttpRes = {
19
19
  headers?: {
20
20
  [key: string]: string | string[];
21
21
  };
22
- body: Json | Buffer;
22
+ body: Json | Uint8Array;
23
23
  };
24
24
  export type HttpArgs<Req extends HttpReq, Res extends HttpRes> = {} & {
25
25
  $req: Req;
package/cmp/esm/main.js CHANGED
@@ -25,14 +25,15 @@ var main_default = (args, params) => {
25
25
  // Avoid `camelCase` util - want to keep this sovereign
26
26
  body: [Object, Array].some((C) => cl.isCls(reqBody, C)) ? JSON.stringify(reqBody) : reqBody !== null ? `${reqBody}` : null
27
27
  };
28
+ const err = new Error("");
28
29
  const abort = new AbortController();
29
30
  const prm = fetch(url, { ...reqArgs, signal: abort.signal }).then(
30
31
  async (res) => {
31
32
  const resBody = await (async () => {
32
- const t = await res.text();
33
+ const t = await res.bytes();
33
34
  try {
34
- return JSON.parse(t);
35
- } catch (err) {
35
+ return JSON.parse(t[cl.toStr]());
36
+ } catch (err2) {
36
37
  }
37
38
  return t;
38
39
  })();
@@ -45,10 +46,10 @@ var main_default = (args, params) => {
45
46
  if (res.status >= 400) throw Error("http reject")[cl.mod](http);
46
47
  return http;
47
48
  },
48
- (err) => {
49
- while (cl.isCls(err.cause, Error)) err = err.cause;
50
- if (err.code === "ENOTFOUND") return err[cl.fire]({ retry: false });
51
- throw err;
49
+ (cause) => {
50
+ while (cl.isCls(cause.cause, Error)) cause = cause.cause;
51
+ if (cause.code === "ENOTFOUND") return err[cl.fire]({ cause, retry: false });
52
+ return err[cl.fire]({ cause });
52
53
  }
53
54
  );
54
55
  return Object.assign(prm, { end: () => abort.abort(Error("fetch aborted")[cl.suppress]()) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gershy/util-http",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "author": "Gershom Maes",
5
5
  "description": "TODO",
6
6
  "keywords": [
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "license": "ISC",
22
22
  "peerDependencies": {
23
- "@gershy/clearing": "^0.0.42"
23
+ "@gershy/clearing": "^0.0.44"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/node": "^24.10.1"