Skip to content

Fix error serialization in frontend notifications#123

Open
htrex wants to merge 1 commit intodevnen:mainfrom
htrex:fix/frontend-error-serialization
Open

Fix error serialization in frontend notifications#123
htrex wants to merge 1 commit intodevnen:mainfrom
htrex:fix/frontend-error-serialization

Conversation

@htrex
Copy link
Contributor

@htrex htrex commented Feb 19, 2026

Summary

Fixes frontend displaying [object Object] instead of actual error messages when the backend returns validation errors.

Problem

When the backend returns a Pydantic validation error (HTTP 422), the detail field is an array of objects, not a string:

{
  "detail": [
    {
      "type": "less_than_equal",
      "loc": ["body", "chunk_size"],
      "msg": "Input should be less than or equal to 500",
      "input": 510
    }
  ]
}

The frontend passed errorResult.detail directly to new Error(), which called .toString() on the array and displayed "[object Object]" to the user.

Steps to reproduce

  1. Enable text splitting in the UI
  2. Set the chunk size slider to a value above 500 (e.g. 510)
  3. Click "Generate Speech"
  4. Observe [object Object] in the error notification

Solution

Added a formatErrorDetail() utility function that handles all API error response formats:

  • String (standard HTTPException): returned as-is
  • Array (Pydantic 422 validation errors): extracts the .msg field from each entry and joins them with "; "
  • Object (unexpected format): falls back to JSON.stringify()

Applied to all 4 error handling paths in script.js:

  • UI state save errors
  • Model configuration errors
  • TTS generation errors
  • Settings reset errors

After fix

The error notification now correctly displays: "Input should be less than or equal to 500"

Test Plan

  • Set chunk size > 500, generate speech → verify readable error message appears
  • Trigger a standard server error (e.g. no voice selected) → verify error still displays correctly
  • Save settings with invalid values → verify error message is readable

Pydantic validation errors (HTTP 422) return `detail` as an array of
objects, not a string. The frontend passed this directly to `new Error()`,
which called `.toString()` on the array and displayed "[object Object]"
to the user instead of the actual error message.

Add `formatErrorDetail()` helper that handles all response formats:
- String: returned as-is
- Array (Pydantic 422): extracts `.msg` from each entry, joins with ";"
- Object: falls back to JSON.stringify()

Applied to all 4 error handling paths in script.js.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant