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:
parent
93e364466a
commit
95324aec79
@ -43,8 +43,12 @@ class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const error = await response.json().catch(() => ({ detail: 'Request failed' }));
|
const errorData = await response.json().catch(() => ({ detail: 'Request failed' }));
|
||||||
throw new Error(error.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) {
|
if (response.status === 204) {
|
||||||
@ -55,10 +59,31 @@ class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async login(email, password) {
|
async login(email, password) {
|
||||||
const data = await this.request('/auth/login', {
|
const response = await fetch(`${API_BASE}/auth/login`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
body: JSON.stringify({ email, password }),
|
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);
|
this.setToken(data.access_token);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,7 +82,7 @@
|
|||||||
|
|
||||||
<div class="demo-credentials">
|
<div class="demo-credentials">
|
||||||
<p><strong>Demo Admin:</strong></p>
|
<p><strong>Demo Admin:</strong></p>
|
||||||
<p>Email: admin@moxiegen.local</p>
|
<p>Email: admin@moxiegen.com</p>
|
||||||
<p>Password: admin123</p>
|
<p>Password: admin123</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user