修复二维码生成器问题

This commit is contained in:
2026-04-02 01:32:52 +08:00
parent e8a11909de
commit 5a8a6db0e5
2 changed files with 17 additions and 7 deletions

View File

@@ -24,7 +24,6 @@ function isLoggedIn() {
// ========== API 请求封装 ==========
async function apiRequest(endpoint, options = {}) {
// 使用 window.API_BASE如果未定义则使用默认值
const baseUrl = window.API_BASE || '/api/v1';
const url = endpoint.startsWith('http') ? endpoint : `${baseUrl}${endpoint}`;
@@ -52,11 +51,21 @@ async function apiRequest(endpoint, options = {}) {
return null;
}
const data = await response.json();
// 先获取响应文本,用于调试
const text = await response.text();
if (!response.ok) {
throw new Error(data.detail || data.message || '请求失败');
let errorMsg;
try {
const errorData = JSON.parse(text);
errorMsg = errorData.detail || errorData.message || JSON.stringify(errorData);
} catch (e) {
errorMsg = text || '请求失败';
}
throw new Error(errorMsg);
}
return data;
return JSON.parse(text);
} catch (error) {
console.error('API 请求错误:', error);
throw error;