diff --git a/client/src/api/client.ts b/client/src/api/client.ts index 4f1598b..33ce717 100644 --- a/client/src/api/client.ts +++ b/client/src/api/client.ts @@ -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();