diff --git a/frontend/src/pages/TreeEditorPage.tsx b/frontend/src/pages/TreeEditorPage.tsx index 695d9237..a21097b4 100644 --- a/frontend/src/pages/TreeEditorPage.tsx +++ b/frontend/src/pages/TreeEditorPage.tsx @@ -349,8 +349,23 @@ export function TreeEditorPage() { toast.success('Tree published successfully') navigate(`/trees/${newTree.id}/edit`, { replace: true }) } - } catch (err) { + } catch (err: unknown) { console.error('Failed to publish tree:', err) + if (err && typeof err === 'object' && 'response' in err) { + const axiosErr = err as { response?: { status?: number; data?: { detail?: string | { message?: string; errors?: Array } } } } + if (axiosErr.response?.status === 422) { + const detail = axiosErr.response.data?.detail + if (typeof detail === 'object' && detail?.errors) { + const messages = detail.errors.map(e => typeof e === 'string' ? e : e.message || 'Unknown error') + toast.error(`Cannot publish: ${messages.join(', ')}`) + } else if (typeof detail === 'string') { + toast.error(`Cannot publish: ${detail}`) + } else { + toast.error('Tree has validation errors. Fix them before publishing.') + } + return + } + } toast.error('Failed to publish tree. Please try again.') } finally { setSaving(false)