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:
chihlasm
2026-03-11 23:56:45 -04:00
parent 458c2d9cab
commit 92c86cab80

View File

@@ -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)
}