fix: fix Docker dev proxy and handle non-JSON error responses in frontend

This commit is contained in:
2026-04-02 14:48:40 +08:00
parent 0905b0302b
commit 5f76abec8b
3 changed files with 9 additions and 2 deletions

View File

@@ -63,3 +63,4 @@ services:
- "5173:5173"
environment:
NODE_ENV: development
API_URL: http://server:3000

View File

@@ -66,7 +66,13 @@ export async function apiFetch<T>(path: string, options: RequestInit = {}): Prom
}
}
const json: ApiResponse<T> = await res.json();
const text = await res.text();
let json: ApiResponse<T>;
try {
json = JSON.parse(text);
} catch {
throw new Error(`Server error (${res.status})`);
}
if (!json.success) {
throw new Error(json.error?.message || 'Request failed');
}

View File

@@ -7,7 +7,7 @@ export default defineConfig({
server: {
port: 5173,
proxy: {
'/api': 'http://localhost:3000',
'/api': process.env.API_URL || 'http://localhost:3000',
},
},
});