Skip to content

fix(hosting): render Inertia error page for browser validation errors (#170) - #181

Merged
antosubash merged 3 commits into
mainfrom
fix/170-validation-error-inertia-page
May 25, 2026
Merged

fix(hosting): render Inertia error page for browser validation errors (#170)#181
antosubash merged 3 commits into
mainfrom
fix/170-validation-error-inertia-page

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Summary

  • Added RequestValidationError handler that checks the Accept header
  • Browser requests (text/html) get a styled Inertia 422 error page instead of raw JSON
  • API/JSON clients continue to receive the standard validation error response

Fixes #170

Test plan

  • curl -H "Accept: text/html" http://localhost:8000/gis/app/datasets/not-a-uuid returns styled error page
  • curl http://localhost:8000/gis/app/datasets/not-a-uuid returns JSON validation errors
  • All 133 hosting tests pass

)

When a browser navigates to a route with an invalid UUID path parameter,
FastAPI raises RequestValidationError which was not handled by the
framework exception handlers, resulting in raw JSON instead of a styled
Inertia error page.

Add a RequestValidationError handler that checks the Accept header:
- Browser requests (text/html) get a friendly 422 Inertia error page
- API/JSON clients get the standard validation detail response
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 25, 2026

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: ab4b8aa
Status:⚡️  Build in progress...

View logs

RequestValidationError.errors() can contain non-JSON-serializable objects
(e.g., ValueError instances in the ctx field). Use FastAPI's
jsonable_encoder to safely serialize the error details in the JSON
response path of request_validation_error_handler.
@antosubash
antosubash merged commit 0cc3f9e into main May 25, 2026
11 of 12 checks passed
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.

Raw JSON error response for invalid UUID path params (browser requests)

1 participant