variant round: roll retired, chance is variant literature (strict parse, crypto pick on reception, picked-only rendering, /story variance metric); entity round: /story the whole deliverable, /table the play projection, the slidwin carry (smart contwin cutoff, whole exchanges, housekeeper reads session-minus-tail); dormant-session rework: universal session lifecycle (dormant->live->finished, sessions/<n> storage), move-at-stop, start lint + auto-send rule, rebaseable housekeeping, turn-0 -> carryover.jsonl, seed -> memory.json, draft-only save-package; format house rules enforced by the nine-rule check-repo (ascii bytes, no text-mutating css); smoke 105/105 + restart + reminder + browser pass green, irene hand-migrated to the new layout
This commit is contained in:
+6
-6
@@ -1,7 +1,7 @@
|
||||
// web/client.mjs — the REST client: the one fetch choke point.
|
||||
// web/client.mjs -- the REST client: the one fetch choke point.
|
||||
//
|
||||
// Every call is logged to the diagnostics (status + duration); a
|
||||
// rejected token ends the session — drop it and show the claim view;
|
||||
// rejected token ends the session -- drop it and show the claim view;
|
||||
// every path leads there until a fresh one is claimed.
|
||||
|
||||
import { logEvent } from './log.mjs';
|
||||
@@ -11,7 +11,7 @@ import { render } from './router.mjs';
|
||||
const TOKEN_KEY = 'rp-token';
|
||||
|
||||
export const authToken = () => { try { return localStorage.getItem(TOKEN_KEY) ?? ''; } catch { return ''; } };
|
||||
export const setToken = (t) => { try { localStorage.setItem(TOKEN_KEY, t); } catch { /* storage blocked — the session just won't persist */ } };
|
||||
export const setToken = (t) => { try { localStorage.setItem(TOKEN_KEY, t); } catch { /* storage blocked -- the session just won't persist */ } };
|
||||
export const clearToken = () => { try { localStorage.removeItem(TOKEN_KEY); } catch { /* same */ } };
|
||||
|
||||
export async function api(path, opts = {}) {
|
||||
@@ -25,14 +25,14 @@ export async function api(path, opts = {}) {
|
||||
...(authToken() ? { authorization: `Bearer ${authToken()}` } : {}),
|
||||
},
|
||||
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
||||
...(opts.keepalive ? { keepalive: true } : {}), // outlives the page — the notepad flush
|
||||
...(opts.keepalive ? { keepalive: true } : {}), // outlives the page -- the notepad flush
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
const e = new Error(data.error ?? `${res.status}`);
|
||||
e.detail = data.detail;
|
||||
e.status = res.status;
|
||||
logEvent('api', `${label} ${res.status} ${Math.round(performance.now() - started)}ms — ${e.message}`);
|
||||
logEvent('api', `${label} ${res.status} ${Math.round(performance.now() - started)}ms -- ${e.message}`);
|
||||
if (res.status === 401 && path !== '/session' && authToken()) {
|
||||
clearToken();
|
||||
state.me = null;
|
||||
@@ -44,7 +44,7 @@ export async function api(path, opts = {}) {
|
||||
logEvent('api', `${label} ${res.status} ${Math.round(performance.now() - started)}ms`);
|
||||
return data;
|
||||
} catch (e) {
|
||||
if (!e.status) logEvent('api', `${label} FAILED ${Math.round(performance.now() - started)}ms — ${e.message}`); // network level
|
||||
if (!e.status) logEvent('api', `${label} FAILED ${Math.round(performance.now() - started)}ms -- ${e.message}`); // network level
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user