Skip to content

Commit f0b6aec

Browse files
authored
fix(viewer): show session-expired toast when loadConfig gets 401 (#1424)
## Problem When a user's Viewer session expires and they navigate to the **Settings** tab, `loadConfig()` fetches `/api/config` which returns HTTP 401. The function silently returns on `!r.ok`, leaving all form fields at their empty/default values. **User-visible symptoms:** - Embedding model field appears blank (even though `openclaw.json` has a valid config) - Clicking "Test Connection" shows: *"❌ 连接失败 — Provider and Model are required"* - No indication that the actual issue is an expired session - Users may think their configuration was lost after a plugin upgrade ## Root Cause ```js // html.ts — loadConfig() const r = await fetch('/api/config'); if (!r.ok) return; // ← silently swallows 401 ``` Other settings functions already handle this correctly: | Function | 401 handling | |---|---| | `doSaveConfig()` | ✅ `toast(t('settings.session.expired'), 'error')` | | `saveModelsConfig()` | ✅ `toast(t('settings.session.expired'), 'error')` | | `testModel()` | ✅ Shows expired message in result element | | **`loadConfig()`** | ❌ Silent return — **this PR** | ## Fix One-line addition: check for 401 before the generic `!r.ok` guard, show the same session-expired toast that other functions use. ```diff async function loadConfig(){ try{ const r=await fetch('/api/config'); + if(r.status===401){toast(t('settings.session.expired'),'error');return;} if(!r.ok) return; ``` No new i18n keys — reuses existing `settings.session.expired`. ## Testing 1. Open Viewer → Settings tab (should load normally) 2. Wait for session to expire (or manually delete the session cookie) 3. Navigate away from Settings and back 4. **Before fix:** Blank form, no error 5. **After fix:** Toast "登录已过期,请刷新页面重新登录" Made with [Cursor](https://cursor.com)
2 parents c044b25 + f90deb3 commit f0b6aec

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

  • apps/memos-local-openclaw/src/viewer

apps/memos-local-openclaw/src/viewer/html.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7205,6 +7205,7 @@ function onProviderChange(){}
72057205
async function loadConfig(){
72067206
try{
72077207
const r=await fetch('/api/config');
7208+
if(r.status===401){toast(t('settings.session.expired'),'error');return;}
72087209
if(!r.ok) return;
72097210
const cfg=await r.json();
72107211
const emb=cfg.embedding||{};

0 commit comments

Comments
 (0)