@emeryld/rrroutes-client 2.2.16 → 2.2.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.
- package/dist/index.cjs +30 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +29 -4
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.fetch.d.ts +12 -0
- package/dist/routesV3.client.types.d.ts +6 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
+
HttpError: () => HttpError,
|
|
34
35
|
SocketClient: () => SocketClient,
|
|
35
36
|
buildRoomPayloadSchema: () => buildRoomPayloadSchema,
|
|
36
37
|
buildRouter: () => buildRouter,
|
|
@@ -44,6 +45,19 @@ __export(index_exports, {
|
|
|
44
45
|
module.exports = __toCommonJS(index_exports);
|
|
45
46
|
|
|
46
47
|
// src/routesV3.client.fetch.ts
|
|
48
|
+
var HttpError = class extends Error {
|
|
49
|
+
constructor(args) {
|
|
50
|
+
const { res, url, body } = args;
|
|
51
|
+
super(`[${res.status}] ${res.statusText}${body ? ` - ${body}` : ""}`);
|
|
52
|
+
this.message = `${this.message}`;
|
|
53
|
+
this.name = "HttpError";
|
|
54
|
+
this.status = res.status;
|
|
55
|
+
this.statusText = res.statusText;
|
|
56
|
+
this.url = url;
|
|
57
|
+
this.body = body;
|
|
58
|
+
this.headers = res.headers ? Object.fromEntries(res.headers.entries()) : {};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
47
61
|
var defaultFetcher = async (req) => {
|
|
48
62
|
const headers = { ...req.headers ?? {} };
|
|
49
63
|
const isFormData = typeof FormData !== "undefined" && req.body instanceof FormData;
|
|
@@ -58,13 +72,24 @@ var defaultFetcher = async (req) => {
|
|
|
58
72
|
});
|
|
59
73
|
const text = await res.text();
|
|
60
74
|
if (!res.ok) {
|
|
61
|
-
|
|
62
|
-
|
|
75
|
+
throw new HttpError({
|
|
76
|
+
res,
|
|
77
|
+
url: req.url,
|
|
78
|
+
body: text
|
|
79
|
+
});
|
|
63
80
|
}
|
|
64
81
|
try {
|
|
65
|
-
return
|
|
82
|
+
return {
|
|
83
|
+
data: JSON.parse(text),
|
|
84
|
+
headers: res.headers ? Object.fromEntries(res.headers.entries()) : {},
|
|
85
|
+
status: res.status
|
|
86
|
+
};
|
|
66
87
|
} catch {
|
|
67
|
-
return
|
|
88
|
+
return {
|
|
89
|
+
data: text,
|
|
90
|
+
headers: res.headers ? Object.fromEntries(res.headers.entries()) : {},
|
|
91
|
+
status: res.status
|
|
92
|
+
};
|
|
68
93
|
}
|
|
69
94
|
};
|
|
70
95
|
|
|
@@ -1734,6 +1759,7 @@ var SocketClient = class {
|
|
|
1734
1759
|
};
|
|
1735
1760
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1736
1761
|
0 && (module.exports = {
|
|
1762
|
+
HttpError,
|
|
1737
1763
|
SocketClient,
|
|
1738
1764
|
buildRoomPayloadSchema,
|
|
1739
1765
|
buildRouter,
|