fix(api): 处理401错误时重定向到登录页

docs(guide): 更新免费计划适用场景的描述
This commit is contained in:
anghunk
2026-01-22 11:05:56 +08:00
parent 286bbaa827
commit ec7ec41c77
2 changed files with 15 additions and 1 deletions

View File

@@ -35,6 +35,20 @@ async function request<T>(method: HttpMethod, path: string, body?: unknown): Pro
}
if (!res.ok) {
const message = data && data.message ? data.message : `请求失败,状态码 ${res.status}`;
if (res.status === 401 && (message === 'Token expired or invalid' || message === 'Unauthorized')) {
localStorage.removeItem('cwd_admin_token');
if (typeof window !== 'undefined') {
try {
const url = new URL(window.location.href);
url.pathname = '/login';
url.search = '';
url.hash = '';
window.location.href = url.toString();
} catch {
window.location.href = '/login';
}
}
}
throw new Error(message);
}
return data as T;

View File

@@ -21,7 +21,7 @@
| 行写入 | 10 万 | ~2 次/次访问 | 5 万次页面访问 |
| 存储 | 5GB | 1-2KB/评论 | 250 万 + 评论 |
**足以满足以下场景:**
**足以满足以下场景:** 对于个人博客或中小型站点来说,免费计划完全够用。
- 日访问量30,000 - 50,000 次页面加载
- 日评论量100 - 200 条新评论