-
Notifications
You must be signed in to change notification settings - Fork 8.4k
fix: API endpoints return JSON 404 instead of HTML when resource not found #11473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: API endpoints return JSON 404 instead of HTML when resource not found #11473
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
WalkthroughThe changes fix API endpoints incorrectly returning frontend HTML for missing resources by explicitly propagating 404 errors. The static file handler now re-raises exceptions for /api/ routes instead of serving index.html, ensuring API 404s surface properly. Endpoints add explicit error handling to return 404 for missing variables and files. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 6 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
e54a6da to
ac800a6
Compare
Summary
Fixes #11458
Problem
When requesting a non-existent resource via API routes (e.g.,
GET /api/v1/projects/{id}), the API was returning status 200 with HTML content instead of a proper 404 JSON response. All API routes were affected by this behavior, caused by the SPA fallback handler insetup_static_files()catching all 404 errors and returningindex.html.Solution
/api/and re-raise the exception to let FastAPI handle it properlyvariable.pydelete endpoint to return 404 instead of 500files.pyedit endpoint to return 404 instead of 500Test plan
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.