github-actions[bot] commited on
Commit
7e18e50
·
1 Parent(s): 7072a89

deploy: b58e3a0 — 更新 api.js

Browse files
Files changed (1) hide show
  1. frontend/src/api.js +11 -14
frontend/src/api.js CHANGED
@@ -1,22 +1,19 @@
1
  const BASE = "/api";
2
 
3
  async function request(method, path, body) {
4
- var res;
5
- try {
6
- res = await fetch(BASE + path, {
7
- method: method,
8
- headers: { "Content-Type": "application/json" },
9
- body: body ? JSON.stringify(body) : undefined,
10
- });
11
- } catch (networkErr) {
12
- throw new Error("Network error. Check your connection and try again.");
13
- }
14
 
15
- var data;
16
  try {
17
- data = await res.json();
18
- } catch (parseErr) {
19
- throw new Error("Server returned non-JSON response (HTTP " + res.status + "). Please try again.");
20
  }
21
 
22
  if (!data.success) throw new Error(data.error || "Request failed");
 
1
  const BASE = "/api";
2
 
3
  async function request(method, path, body) {
4
+ const res = await fetch(BASE + path, {
5
+ method: method,
6
+ headers: { "Content-Type": "application/json" },
7
+ body: body ? JSON.stringify(body) : undefined,
8
+ });
9
+
10
+ const text = await res.text();
 
 
 
11
 
12
+ let data;
13
  try {
14
+ data = JSON.parse(text);
15
+ } catch (e) {
16
+ throw new Error("HTTP " + res.status + " -- server returned: " + text.slice(0, 200));
17
  }
18
 
19
  if (!data.success) throw new Error(data.error || "Request failed");