fix: Improve error handling and update demo credentials

- Better error parsing for FastAPI validation errors
- Updated login demo credentials to admin@moxiegen.com
- Improved login API error handling
This commit is contained in:
Z User 2026-03-24 03:19:43 +00:00
parent 93e364466a
commit 95324aec79
2 changed files with 29 additions and 4 deletions

View File

@ -43,8 +43,12 @@ class ApiClient {
}
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: 'Request failed' }));
throw new Error(error.detail || 'Request failed');
const errorData = await response.json().catch(() => ({ detail: 'Request failed' }));
// Handle FastAPI validation errors
if (errorData.detail && typeof errorData.detail === 'object') {
throw new Error(JSON.stringify(errorData.detail));
}
throw new Error(errorData.detail || 'Request failed');
}
if (response.status === 204) {
@ -55,10 +59,31 @@ class ApiClient {
}
async login(email, password) {
const data = await this.request('/auth/login', {
const response = await fetch(`${API_BASE}/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email, password }),
});
const data = await response.json().catch(() => ({}));
if (!response.ok) {
if (data.detail) {
if (typeof data.detail === 'string') {
throw new Error(data.detail);
}
// Validation errors
if (Array.isArray(data.detail)) {
const messages = data.detail.map(e => e.msg).join(', ');
throw new Error(messages);
}
throw new Error(JSON.stringify(data.detail));
}
throw new Error('Login failed');
}
this.setToken(data.access_token);
return data;
}

View File

@ -82,7 +82,7 @@
<div class="demo-credentials">
<p><strong>Demo Admin:</strong></p>
<p>Email: admin@moxiegen.local</p>
<p>Email: admin@moxiegen.com</p>
<p>Password: admin123</p>
</div>
</div>