Spaces:
Sleeping
Sleeping
link0518
commited on
Commit
·
8f02d2f
1
Parent(s):
587e16b
中转
Browse files- src/api/client.js +12 -1
- src/utils/logger.js +2 -2
src/api/client.js
CHANGED
|
@@ -123,7 +123,18 @@ export async function getAvailableModels() {
|
|
| 123 |
body: JSON.stringify({})
|
| 124 |
});
|
| 125 |
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
return {
|
| 129 |
object: 'list',
|
|
|
|
| 123 |
body: JSON.stringify({})
|
| 124 |
});
|
| 125 |
|
| 126 |
+
if (!response.ok) {
|
| 127 |
+
const errorText = await response.text();
|
| 128 |
+
throw new Error(`获取模型列表失败 (${response.status}): ${errorText}`);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
const responseText = await response.text();
|
| 132 |
+
let data;
|
| 133 |
+
try {
|
| 134 |
+
data = JSON.parse(responseText);
|
| 135 |
+
} catch (e) {
|
| 136 |
+
throw new Error(`JSON解析失败: ${e.message}. 原始响应: ${responseText.substring(0, 200)}`);
|
| 137 |
+
}
|
| 138 |
|
| 139 |
return {
|
| 140 |
object: 'list',
|
src/utils/logger.js
CHANGED
|
@@ -10,12 +10,12 @@ const colors = {
|
|
| 10 |
function logMessage(level, ...args) {
|
| 11 |
const timestamp = new Date().toLocaleTimeString('zh-CN', { hour12: false });
|
| 12 |
const color = { info: colors.green, warn: colors.yellow, error: colors.red }[level];
|
| 13 |
-
console.
|
| 14 |
}
|
| 15 |
|
| 16 |
function logRequest(method, path, status, duration) {
|
| 17 |
const statusColor = status >= 500 ? colors.red : status >= 400 ? colors.yellow : colors.green;
|
| 18 |
-
console.
|
| 19 |
}
|
| 20 |
|
| 21 |
export const log = {
|
|
|
|
| 10 |
function logMessage(level, ...args) {
|
| 11 |
const timestamp = new Date().toLocaleTimeString('zh-CN', { hour12: false });
|
| 12 |
const color = { info: colors.green, warn: colors.yellow, error: colors.red }[level];
|
| 13 |
+
console.error(`${colors.gray}${timestamp}${colors.reset} ${color}[${level}]${colors.reset}`, ...args);
|
| 14 |
}
|
| 15 |
|
| 16 |
function logRequest(method, path, status, duration) {
|
| 17 |
const statusColor = status >= 500 ? colors.red : status >= 400 ? colors.yellow : colors.green;
|
| 18 |
+
console.error(`${colors.cyan}[${method}]${colors.reset} - ${path} ${statusColor}${status}${colors.reset} ${colors.gray}${duration}ms${colors.reset}`);
|
| 19 |
}
|
| 20 |
|
| 21 |
export const log = {
|