@4yi/cli 0.1.0 → 0.1.2
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 +1 -1
- package/src/config.mjs +1 -1
- package/src/http.mjs +11 -2
package/package.json
CHANGED
package/src/config.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
|
-
export const DEFAULT_BASE_URL = "https://
|
|
5
|
+
export const DEFAULT_BASE_URL = "https://xclaw-dev.bieases.com";
|
|
6
6
|
|
|
7
7
|
export function normalizeBaseUrl(value) {
|
|
8
8
|
return String(value || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
package/src/http.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export async function requestJson(baseUrl, path, options = {}) {
|
|
2
|
-
const
|
|
2
|
+
const url = `${baseUrl}${path}`;
|
|
3
|
+
const res = await fetch(url, {
|
|
3
4
|
...options,
|
|
4
5
|
headers: {
|
|
5
6
|
"content-type": "application/json",
|
|
@@ -8,7 +9,15 @@ export async function requestJson(baseUrl, path, options = {}) {
|
|
|
8
9
|
},
|
|
9
10
|
});
|
|
10
11
|
const text = await res.text();
|
|
11
|
-
|
|
12
|
+
let body = null;
|
|
13
|
+
if (text) {
|
|
14
|
+
try {
|
|
15
|
+
body = JSON.parse(text);
|
|
16
|
+
} catch {
|
|
17
|
+
const contentType = res.headers.get("content-type") || "unknown content type";
|
|
18
|
+
throw new Error(`Expected JSON from ${url} but received ${contentType} (HTTP ${res.status})`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
12
21
|
if (!res.ok) {
|
|
13
22
|
const message = body?.error?.message || body?.error || `HTTP ${res.status}`;
|
|
14
23
|
const err = new Error(message);
|