fix: show detailed validation error messages on client
Parse field-specific errors from server response instead of showing generic "Validation error" message. Applies to both request() and upload() methods in the API client. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -36,7 +36,14 @@ class ApiClient {
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ message: 'Request failed' }));
|
||||
throw new ApiError(error.message || `HTTP ${response.status}`, response.status, error);
|
||||
let message = error.message || `HTTP ${response.status}`;
|
||||
if (error.errors && typeof error.errors === 'object') {
|
||||
const details = Object.entries(error.errors)
|
||||
.map(([field, msgs]) => `${field}: ${Array.isArray(msgs) ? msgs.join(', ') : msgs}`)
|
||||
.join('; ');
|
||||
if (details) message = details;
|
||||
}
|
||||
throw new ApiError(message, response.status, error);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
@@ -75,7 +82,14 @@ class ApiClient {
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ message: 'Upload failed' }));
|
||||
throw new Error(error.message || `HTTP ${response.status}`);
|
||||
let message = error.message || `HTTP ${response.status}`;
|
||||
if (error.errors && typeof error.errors === 'object') {
|
||||
const details = Object.entries(error.errors)
|
||||
.map(([field, msgs]) => `${field}: ${Array.isArray(msgs) ? msgs.join(', ') : msgs}`)
|
||||
.join('; ');
|
||||
if (details) message = details;
|
||||
}
|
||||
throw new ApiError(message, response.status, error);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
|
||||
Reference in New Issue
Block a user