Spaces:
Sleeping
Sleeping
orakzai-io commited on
Commit ·
5083221
1
Parent(s): 87b8339
error handling
Browse files- frontend/src/api/client.ts +4 -4
- frontend/src/lib/auth.ts +6 -6
- frontend/vite.config.ts +10 -1
- vercel.json +0 -34
frontend/src/api/client.ts
CHANGED
|
@@ -28,8 +28,8 @@ export async function uploadDocument(file: File): Promise<void> {
|
|
| 28 |
});
|
| 29 |
|
| 30 |
if (!res.ok) {
|
| 31 |
-
const errData = await res.json();
|
| 32 |
-
throw new Error(errData.detail ||
|
| 33 |
}
|
| 34 |
}
|
| 35 |
|
|
@@ -69,8 +69,8 @@ export async function streamChat(
|
|
| 69 |
});
|
| 70 |
|
| 71 |
if (!res.ok) {
|
| 72 |
-
const errData = await res.json();
|
| 73 |
-
throw new Error(errData.detail ||
|
| 74 |
}
|
| 75 |
|
| 76 |
if (!res.body) throw new Error('No response body for streaming');
|
|
|
|
| 28 |
});
|
| 29 |
|
| 30 |
if (!res.ok) {
|
| 31 |
+
const errData = await res.json().catch(() => ({}));
|
| 32 |
+
throw new Error(errData.detail || `Upload failed (${res.status})`);
|
| 33 |
}
|
| 34 |
}
|
| 35 |
|
|
|
|
| 69 |
});
|
| 70 |
|
| 71 |
if (!res.ok) {
|
| 72 |
+
const errData = await res.json().catch(() => ({}));
|
| 73 |
+
throw new Error(errData.detail || `Chat request failed (${res.status})`);
|
| 74 |
}
|
| 75 |
|
| 76 |
if (!res.body) throw new Error('No response body for streaming');
|
frontend/src/lib/auth.ts
CHANGED
|
@@ -39,8 +39,8 @@ export async function login(payload: LoginPayload): Promise<AuthResponse> {
|
|
| 39 |
});
|
| 40 |
|
| 41 |
if (!res.ok) {
|
| 42 |
-
const errData = await res.json();
|
| 43 |
-
throw new Error(errData.detail ||
|
| 44 |
}
|
| 45 |
|
| 46 |
return res.json();
|
|
@@ -54,8 +54,8 @@ export async function register(payload: RegisterPayload): Promise<UserInfo> {
|
|
| 54 |
});
|
| 55 |
|
| 56 |
if (!res.ok) {
|
| 57 |
-
const errData = await res.json();
|
| 58 |
-
throw new Error(errData.detail?.[0]?.msg || errData.detail ||
|
| 59 |
}
|
| 60 |
|
| 61 |
return res.json();
|
|
@@ -71,8 +71,8 @@ export async function logout(): Promise<void> {
|
|
| 71 |
});
|
| 72 |
|
| 73 |
if (!res.ok) {
|
| 74 |
-
const errData = await res.json();
|
| 75 |
-
throw new Error(errData.detail ||
|
| 76 |
}
|
| 77 |
}
|
| 78 |
|
|
|
|
| 39 |
});
|
| 40 |
|
| 41 |
if (!res.ok) {
|
| 42 |
+
const errData = await res.json().catch(() => ({}));
|
| 43 |
+
throw new Error(errData.detail || `Login failed (${res.status})`);
|
| 44 |
}
|
| 45 |
|
| 46 |
return res.json();
|
|
|
|
| 54 |
});
|
| 55 |
|
| 56 |
if (!res.ok) {
|
| 57 |
+
const errData = await res.json().catch(() => ({}));
|
| 58 |
+
throw new Error(errData.detail?.[0]?.msg || errData.detail || `Registration failed (${res.status})`);
|
| 59 |
}
|
| 60 |
|
| 61 |
return res.json();
|
|
|
|
| 71 |
});
|
| 72 |
|
| 73 |
if (!res.ok) {
|
| 74 |
+
const errData = await res.json().catch(() => ({}));
|
| 75 |
+
throw new Error(errData.detail || `Logout failed (${res.status})`);
|
| 76 |
}
|
| 77 |
}
|
| 78 |
|
frontend/vite.config.ts
CHANGED
|
@@ -4,4 +4,13 @@ import react from '@vitejs/plugin-react'
|
|
| 4 |
// https://vite.dev/config/
|
| 5 |
export default defineConfig({
|
| 6 |
plugins: [react()],
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
// https://vite.dev/config/
|
| 5 |
export default defineConfig({
|
| 6 |
plugins: [react()],
|
| 7 |
+
server: {
|
| 8 |
+
proxy: {
|
| 9 |
+
'/api': {
|
| 10 |
+
target: 'http://localhost:8000',
|
| 11 |
+
changeOrigin: true,
|
| 12 |
+
rewrite: (path) => path.replace(/^\/api/, ''),
|
| 13 |
+
},
|
| 14 |
+
},
|
| 15 |
+
},
|
| 16 |
+
})
|
vercel.json
DELETED
|
@@ -1,34 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"services": {
|
| 3 |
-
"web": {
|
| 4 |
-
"root": "frontend",
|
| 5 |
-
"framework": "vite"
|
| 6 |
-
},
|
| 7 |
-
"api": {
|
| 8 |
-
"root": "backend",
|
| 9 |
-
"entrypoint": "main.py"
|
| 10 |
-
}
|
| 11 |
-
},
|
| 12 |
-
"rewrites": [
|
| 13 |
-
{
|
| 14 |
-
"source": "/api/(.*)",
|
| 15 |
-
"destination": {
|
| 16 |
-
"service": "api",
|
| 17 |
-
"path": "/$1"
|
| 18 |
-
}
|
| 19 |
-
},
|
| 20 |
-
{
|
| 21 |
-
"source": "/((?!api/|.*\\..*).*)",
|
| 22 |
-
"destination": {
|
| 23 |
-
"service": "web",
|
| 24 |
-
"path": "/index.html"
|
| 25 |
-
}
|
| 26 |
-
},
|
| 27 |
-
{
|
| 28 |
-
"source": "/(.*)",
|
| 29 |
-
"destination": {
|
| 30 |
-
"service": "web"
|
| 31 |
-
}
|
| 32 |
-
}
|
| 33 |
-
]
|
| 34 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|