DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(voice): surface the HTTP status when a preview error body is not JSON
Wen Li Hong9a80d3477fd7
diff --git a/web/components/settings/VoicePreviewPanel.tsx b/web/components/settings/VoicePreviewPanel.tsxindex e3b93b8e0..620779145 100644--- a/web/components/settings/VoicePreviewPanel.tsx+++ b/web/components/settings/VoicePreviewPanel.tsx@@ -81,9 +81,14 @@ function PreviewRequest({body: JSON.stringify({ catalog: draft, profile_id: profileId, model_id: modelId, text }),})if (!response.ok) {- const payload = await response.json()+ // A reverse proxy can replace the backend's JSON error with an HTML+ // page; parse defensively and surface the status instead of the+ // resulting JSON syntax error.+ const payload = (await response.json().catch(() => ({}))) as { detail?: unknown }throw new Error(- typeof payload.detail === 'string' ? payload.detail : 'Voice preview failed.'+ typeof payload.detail === 'string' && payload.detail.trim()+ ? payload.detail+ : t('Voice preview failed (HTTP {{status}}).', { status: response.status }))}const audio = await response.blob()diff --git a/web/locales/de/app.json b/web/locales/de/app.jsonindex 512a4fa8c..62a15e0f6 100644--- a/web/locales/de/app.json+++ b/web/locales/de/app.json@@ -4519,6 +4519,7 @@"Uses the current form without saving. Choose text in the voice's language. The provider may charge for this synthesis.": "Nutzt das aktuelle Formular, ohne zu speichern. Wähle Text in der Sprache der Stimme. Der Provider kann diese Synthese in Rechnung stellen.","Generated voice preview": "Erzeugte Stimmen-Vorschau","Voice preview failed.": "Stimmen-Vorschau fehlgeschlagen.",+ "Voice preview failed (HTTP {{status}}).": "Stimmen-Vorschau fehlgeschlagen (HTTP {{status}}).","The provider returned no playable audio.": "Der Provider hat kein abspielbares Audio zurückgegeben.","Voice preview was cancelled or timed out.": "Die Stimmen-Vorschau wurde abgebrochen oder hat das Zeitlimit überschritten.","Voice preview failed. Check the provider credentials, model, voice, language and format.": "Stimmen-Vorschau fehlgeschlagen. Überprüfe Provider-Anmeldedaten, Modell, Stimme, Sprache und Format.",diff --git a/web/locales/en/app.json b/web/locales/en/app.jsonindex cb2ea0b37..ccdb0cd97 100644--- a/web/locales/en/app.json+++ b/web/locales/en/app.json@@ -4522,6 +4522,7 @@"Uses the current form without saving. Choose text in the voice's language. The provider may charge for this synthesis.": "Uses the current form without saving. Choose text in the voice's language. The provider may charge for this synthesis.","Generated voice preview": "Generated voice preview","Voice preview failed.": "Voice preview failed.",+ "Voice preview failed (HTTP {{status}}).": "Voice preview failed (HTTP {{status}}).","The provider returned no playable audio.": "The provider returned no playable audio.","Voice preview was cancelled or timed out.": "Voice preview was cancelled or timed out.","Voice preview failed. Check the provider credentials, model, voice, language and format.": "Voice preview failed. Check the provider credentials, model, voice, language and format.",diff --git a/web/locales/pl/app.json b/web/locales/pl/app.jsonindex d4df149c3..190e113ff 100644--- a/web/locales/pl/app.json+++ b/web/locales/pl/app.json@@ -4518,6 +4518,7 @@"Uses the current form without saving. Choose text in the voice's language. The provider may charge for this synthesis.": "Korzysta z bieżących ustawień bez zapisywania. Wybierz tekst w języku głosu. Dostawca może naliczyć opłatę za tę syntezę.","Generated voice preview": "Wygenerowany podgląd głosu","Voice preview failed.": "Nie udało się wygenerować podglądu głosu.",+ "Voice preview failed (HTTP {{status}}).": "Nie udało się wygenerować podglądu głosu (HTTP {{status}}).","The provider returned no playable audio.": "Dostawca nie zwrócił odtwarzalnego dźwięku.","Voice preview was cancelled or timed out.": "Podgląd głosu został anulowany lub przekroczono limit czasu.","Voice preview failed. Check the provider credentials, model, voice, language and format.": "Nie udało się wygenerować podglądu głosu. Sprawdź dane uwierzytelniające dostawcy, model, głos, język i format.",diff --git a/web/locales/uk/app.json b/web/locales/uk/app.jsonindex 71dc92979..1ee133ade 100644--- a/web/locales/uk/app.json+++ b/web/locales/uk/app.json@@ -4533,6 +4533,7 @@"Uses the current form without saving. Choose text in the voice's language. The provider may charge for this synthesis.": "Використовує поточну форму без збереження. Виберіть текст мовою голосу. Провайдер може стягувати плату за цей синтез.","Generated voice preview": "Згенерований попередній перегляд голосу","Voice preview failed.": "Помилка попереднього голосового перегляду.",+ "Voice preview failed (HTTP {{status}}).": "Помилка попереднього голосового перегляду (HTTP {{status}}).","The provider returned no playable audio.": "Провайдер не надав аудіо, яке можна відтворити.","Voice preview was cancelled or timed out.": "Голосовий попередній перегляд скасовано або минув час очікування.","Voice preview failed. Check the provider credentials, model, voice, language and format.": "Помилка попереднього голосового перегляду. Перевірте облікові дані провайдера, модель, голос, мову та формат.",diff --git a/web/locales/zh/app.json b/web/locales/zh/app.jsonindex 760aceb5f..72e2a1c1c 100644--- a/web/locales/zh/app.json+++ b/web/locales/zh/app.json@@ -4522,6 +4522,7 @@"Uses the current form without saving. Choose text in the voice's language. The provider may charge for this synthesis.": "使用当前表单配置,无需保存。请使用音色支持的语言编写文本,提供方可能收取本次合成费用。","Generated voice preview": "生成的试听音频","Voice preview failed.": "音色试听失败。",+ "Voice preview failed (HTTP {{status}}).": "音色试听失败(HTTP {{status}})。","The provider returned no playable audio.": "提供方未返回可播放的音频。","Voice preview was cancelled or timed out.": "音色试听已取消或超时。","Voice preview failed. Check the provider credentials, model, voice, language and format.": "音色试听失败,请检查提供方凭据、模型、音色、语言和音频格式。",diff --git a/web/tests/voice-settings.spec.tsx b/web/tests/voice-settings.spec.tsxindex 9fb6a1a7b..eaef1b744 100644--- a/web/tests/voice-settings.spec.tsx+++ b/web/tests/voice-settings.spec.tsx@@ -17,7 +17,11 @@ vi.mock('@/lib/api', () => ({apiFetch: (...args: unknown[]) => mock.fetch(...args),}))vi.mock('react-i18next', () => ({- useTranslation: () => ({ t: (s: string) => s, i18n: { language: 'en' } }),+ useTranslation: () => ({+ t: (s: string, opts?: Record<string, unknown>) =>+ opts ? s.replace(/\{\{(\w+)\}\}/g, (_m, key: string) => String(opts[key] ?? '')) : s,+ i18n: { language: 'en' },+ }),}))vi.mock('@/hooks/useVoiceAutoplay', () => ({useVoiceAutoplay: () => ({@@ -250,6 +254,23 @@ it('reports failures and allows retry without applying settings', async () => {expect(screen.getByRole('button', { name: 'Preview voice' }).hasAttribute('disabled')).toBe(false)})+it('shows the HTTP status for a non-JSON error body instead of a JSON parse error', async () => {+ mock.fetch.mockResolvedValue({+ ok: false,+ status: 502,+ json: async () => {+ throw new SyntaxError("Unexpected token '<', \"<!DOCTYPE \"... is not valid JSON")+ },+ })+ render(<Harness />)+ fireEvent.click(screen.getByRole('button', { name: 'Preview voice' }))+ await waitFor(() =>+ expect(screen.getByRole('alert').textContent).toBe('Voice preview failed (HTTP 502).')+ )+ expect(screen.queryByText(/Unexpected token/)).toBeNull()+ expect(screen.getByRole('button', { name: 'Preview voice' }).hasAttribute('disabled')).toBe(false)+})+it('lets a slow preview use the configured timeout and cancels at that deadline', async () => {vi.useFakeTimers()try {