Skip to content

Improve 404 handling for browser routes#17

Open
moab01567 wants to merge 1 commit into
testdrivenio:masterfrom
moab01567:imporve-404-handling
Open

Improve 404 handling for browser routes#17
moab01567 wants to merge 1 commit into
testdrivenio:masterfrom
moab01567:imporve-404-handling

Conversation

@moab01567

Copy link
Copy Markdown

Summary

This PR improves the browser experience for unknown routes by adding a simple custom 404 HTML page.

Before this change, unknown routes such as /jnfja returned the default FastAPI 404 Not Found JSON response in the browser. While this is technically correct, it gives a poor user experience for users who access an invalid URL through the browser.

The new custom 404 page explains that the requested page could not be found and gives the user a link back to the homepage. The response still uses status code 404, so the application does not hide the fact that the URL is invalid.

Why not redirect?

I considered redirecting unknown routes back to /, but chose not to do that because it could hide real routing errors. A custom 404 page keeps the error visible while making it easier for users to understand what happened.

Manual testing

  • Verified that http://localhost:8004 still renders the homepage.
  • Verified that http://localhost:8004/jnfja shows the custom 404 page.
  • Verified that the unknown route is not redirected to /.
  • Verified that the change improves the browser experience without changing the purpose of the error handling.

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