ranranrunforit commited on
Commit
3195c21
·
verified ·
1 Parent(s): 79755bf

Update ui_kits/chan-compass/api.js

Browse files
Files changed (1) hide show
  1. ui_kits/chan-compass/api.js +19 -9
ui_kits/chan-compass/api.js CHANGED
@@ -6,14 +6,24 @@ window.CCApi = (function () {
6
  if (!r.ok) throw new Error(await r.text());
7
  return r.json();
8
  }
9
- async function jpost(url, body) {
10
- const r = await fetch(url, {
11
- method: "POST",
12
- headers: { "Content-Type": "application/json" },
13
- body: JSON.stringify(body || {}),
14
- });
15
- if (!r.ok) throw new Error(await r.text());
16
- return r.json();
 
 
 
 
 
 
 
 
 
 
17
  }
18
 
19
  /* Stream an SSE endpoint. onChunk(obj) per message; resolves on `done`. */
@@ -50,4 +60,4 @@ window.CCApi = (function () {
50
  exportDataset: () => jpost("/api/model/export-dataset", {}),
51
  email: (content, to, tag) => jpost("/api/email", { content, to, tag }),
52
  };
53
- })();
 
6
  if (!r.ok) throw new Error(await r.text());
7
  return r.json();
8
  }
9
+ async function jpost(url, body, timeoutMs = 180000) {
10
+ const controller = new AbortController();
11
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
12
+ try {
13
+ const r = await fetch(url, {
14
+ method: "POST",
15
+ headers: { "Content-Type": "application/json" },
16
+ body: JSON.stringify(body || {}),
17
+ signal: controller.signal,
18
+ });
19
+ if (!r.ok) throw new Error(await r.text());
20
+ return r.json();
21
+ } catch (e) {
22
+ if (e.name === "AbortError") throw new Error("Request timed out after " + (timeoutMs / 1000) + "s — the server may still be running. Refresh and try again.");
23
+ throw e;
24
+ } finally {
25
+ clearTimeout(timer);
26
+ }
27
  }
28
 
29
  /* Stream an SSE endpoint. onChunk(obj) per message; resolves on `done`. */
 
60
  exportDataset: () => jpost("/api/model/export-dataset", {}),
61
  email: (content, to, tag) => jpost("/api/email", { content, to, tag }),
62
  };
63
+ })();