Improve deployment safety and chat reliability
Deploy FluentGerman.ai / deploy (push) Successful in 1m25s

This commit is contained in:
2026-08-29 17:28:50 +02:00
parent e9f12bc2ba
commit d974aaedc8
15 changed files with 746 additions and 153 deletions
+19 -5
View File
@@ -52,15 +52,27 @@ async function api(path, options = {}) {
return response;
}
async function apiJSON(path, options = {}) {
const response = await api(path, options);
if (!response || !response.ok) {
const error = await response?.json().catch(() => ({ detail: 'Request failed' }));
throw new Error(error.detail || 'Request failed');
async function ensureOk(response) {
// api() returns undefined after a 401 — the redirect is already under way
if (!response) throw new Error('Session expired');
if (!response.ok) {
const error = await response.json().catch(() => null);
throw new Error(error?.detail || 'Request failed');
}
return response;
}
async function apiJSON(path, options = {}) {
const response = await ensureOk(await api(path, options));
return response.json();
}
/* Same, for endpoints that answer 204 No Content (the deletes). */
async function apiVoid(path, options = {}) {
await ensureOk(await api(path, options));
}
function requireAuth() {
if (!getToken()) {
window.location.href = '/';
@@ -81,6 +93,8 @@ function requireAdmin() {
function logout() {
clearToken();
clearUser();
// Drop the saved conversation as well — shared devices are the norm here
try { sessionStorage.clear(); } catch (e) { /* storage may be blocked */ }
window.location.href = '/';
}