openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Share the apiClient error-message helper across the feedback surface

Open CodeGhost21 opened this issue 3 months ago • 1 comments

Use a concise sentence-case title that describes the work item.

Summary

Lift messageForApiError out of FeedbackSubmitForm.tsx into a shared helper and converge the four other feedback call sites on it, so a server-supplied error message reaches the user instead of being replaced by generic copy.

Problem / Context

apiClient rejects with a plain { success: false, error: "..." } object, not an Error (app/src/services/apiClient.ts:109-111,126,130). Every err instanceof Error ? err.message : t(...) against it therefore takes the fallback branch unconditionally — the server's message is discarded 100% of the time, and the user is told "Something went wrong. Please try again." when the backend explained exactly what was wrong.

tinyhumansai/openhuman#5431 fixed this for the submit form with a file-local messageForApiError, which matters there because the backend quality gate returns the reason a draft was refused. The same pattern is still live at four more sites on the same surface, all going through the same apiClient:

  • app/src/components/feedback/FeedbackComments.tsx:56 — comment load
  • app/src/components/feedback/FeedbackComments.tsx:78 — comment post
  • app/src/components/feedback/FeedbackAdminMenu.tsx:42 — admin status update
  • app/src/pages/Feedback.tsx:82 — board load

Raised in review on #5431 and deliberately left out of that PR as scope. Left alone, each site grows its own copy of the fix.

Scope (optional)

In scope: a single exported helper (services-level, next to apiClient, since the shape it decodes is apiClient's), the four call sites above, and unit coverage for both rejection shapes.

Not in scope: changing what apiClient throws. Making it reject with a real Error would be the deeper fix, but it is a cross-cutting change to every consumer in the app, not a feedback-surface cleanup — worth its own issue if wanted.

Note the helper must keep the fallback for a blank or missing error field, and must not surface a raw payload dump — only the error string.

Acceptance criteria

  • [ ] Shared helper — messageForApiError(err, fallback) lives in one place, handles the Error shape, the { success, error } shape, and falls back on a blank or absent message.
  • [ ] Call sites converged — the four sites above and FeedbackSubmitForm.tsx use it; no instanceof Error check against an apiClient rejection remains on the feedback surface.
  • [ ] Tests — unit coverage for all three branches, plus at least one component test proving a server message reaches the screen at a converged site.
  • [ ] Diff coverage ≥ 80% — the implementing PR meets the changed-lines coverage gate (Vitest + cargo-llvm-cov, enforced by .github/workflows/ci-lite.yml) when code changes are involved.

Related

  • tinyhumansai/openhuman#5431 — where the bug was diagnosed and fixed for the submit form; review thread flagging the other four sites
  • tinyhumansai/openhuman#5430 — the composer quality-tier issue #5431 closes

CodeGhost21 avatar Aug 07 '26 10:08 CodeGhost21

I’ll take a narrow pass on this. I’ll centralize extraction of plain API error messages in a shared frontend helper and update the feedback surfaces that currently discard { error } responses, without changing transport behavior. I’ll add helper edge-case coverage plus a component regression proving the server message renders, then open a draft PR once the focused tests, typecheck, lint, formatting, and changed-line coverage checks are green.

samrusani avatar Aug 20 '26 20:08 samrusani