修复二维码生成器问题
This commit is contained in:
17
js/common.js
17
js/common.js
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user