fix: handle object-shaped validation errors in KB commit error toast
The commit endpoint returns {message, validation_errors} when
validation fails, but the error handler was passing the whole object
to toast.error(), crashing React with "Objects are not valid as a
React child".
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -140,8 +140,14 @@ export default function KBAcceleratorPage() {
|
||||
// Refresh quota
|
||||
kbAcceleratorApi.getQuota().then(setQuota).catch(() => {})
|
||||
} catch (err: unknown) {
|
||||
const message = (err as { response?: { data?: { detail?: string } } })?.response?.data?.detail ?? 'Commit failed'
|
||||
toast.error(message)
|
||||
const detail = (err as { response?: { data?: { detail?: string | { message?: string; validation_errors?: string[] } } } })?.response?.data?.detail
|
||||
if (typeof detail === 'object' && detail !== null) {
|
||||
const msg = detail.message || 'Commit failed'
|
||||
const errors = detail.validation_errors
|
||||
toast.error(errors?.length ? `${msg}\n${errors.join('\n')}` : msg)
|
||||
} else {
|
||||
toast.error(typeof detail === 'string' ? detail : 'Commit failed')
|
||||
}
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user