@emeryld/rrroutes-client 2.2.16 → 2.2.18

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/dist/index.mjs CHANGED
@@ -1,6 +1,19 @@
1
1
  "use client";
2
2
 
3
3
  // src/routesV3.client.fetch.ts
4
+ var HttpError = class extends Error {
5
+ constructor(args) {
6
+ const { res, url, body } = args;
7
+ super(`[${res.status}] ${res.statusText}${body ? ` - ${body}` : ""}`);
8
+ this.message = `${this.message}`;
9
+ this.name = "HttpError";
10
+ this.status = res.status;
11
+ this.statusText = res.statusText;
12
+ this.url = url;
13
+ this.body = body;
14
+ this.headers = res.headers ? Object.fromEntries(res.headers.entries()) : {};
15
+ }
16
+ };
4
17
  var defaultFetcher = async (req) => {
5
18
  const headers = { ...req.headers ?? {} };
6
19
  const isFormData = typeof FormData !== "undefined" && req.body instanceof FormData;
@@ -15,13 +28,24 @@ var defaultFetcher = async (req) => {
15
28
  });
16
29
  const text = await res.text();
17
30
  if (!res.ok) {
18
- const snippet = text.slice(0, 400);
19
- throw new Error(`[${res.status}] ${res.statusText} \u2014 ${snippet}`);
31
+ throw new HttpError({
32
+ res,
33
+ url: req.url,
34
+ body: text
35
+ });
20
36
  }
21
37
  try {
22
- return JSON.parse(text);
38
+ return {
39
+ data: JSON.parse(text),
40
+ headers: res.headers ? Object.fromEntries(res.headers.entries()) : {},
41
+ status: res.status
42
+ };
23
43
  } catch {
24
- return text;
44
+ return {
45
+ data: text,
46
+ headers: res.headers ? Object.fromEntries(res.headers.entries()) : {},
47
+ status: res.status
48
+ };
25
49
  }
26
50
  };
27
51
 
@@ -1699,6 +1723,7 @@ var SocketClient = class {
1699
1723
  }
1700
1724
  };
1701
1725
  export {
1726
+ HttpError,
1702
1727
  SocketClient,
1703
1728
  buildRoomPayloadSchema,
1704
1729
  buildRouter,