Skip to content

Conversation

@AntonioABLima
Copy link
Collaborator

@AntonioABLima AntonioABLima commented Jan 27, 2026

Summary

  • Fix SPA 404 handler intercepting API route errors and returning HTML instead of JSON
  • Add proper 404 handling to variable and file endpoints

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 in setup_static_files() catching all 404 errors and returning index.html.

Solution

  • Modified the 404 exception handler to check if the request path starts with /api/ and re-raise the exception to let FastAPI handle it properly
  • Fixed variable.py delete endpoint to return 404 instead of 500
  • Fixed files.py edit endpoint to return 404 instead of 500

Test plan

  • Unit tests for all API endpoints returning JSON 404
  • Integration tests with static files handler to verify production behavior

Summary by CodeRabbit

  • Bug Fixes
    • API endpoints now return 404 Not Found for missing resources instead of 500 Internal Server Error.
    • HTTP exceptions are properly propagated through error handlers rather than being masked as generic server errors.
    • Static file and API request handling are now properly differentiated for more accurate error responses.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review

Walkthrough

The 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

Cohort / File(s) Summary
API Error Handling
src/backend/base/langflow/api/v1/variable.py, src/backend/base/langflow/api/v2/files.py
Added explicit guards and exception re-raises in delete_variable and edit_file_name to ensure HTTP 404 errors propagate unchanged instead of being masked by generic 500 responses
Static File Route Handler
src/backend/base/langflow/main.py
Updated custom_404_handler to re-raise exceptions for /api/ requests, preventing API 404s from falling through to frontend SPA; non-API requests continue serving index.html as before
Test Update
src/backend/tests/unit/api/v1/test_variable.py
Updated test_delete_variable__exception expectation from 500 to 404 status code to match corrected endpoint behavior

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 6 | ❌ 3
❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Quality And Coverage ⚠️ Warning PR lacks sufficient test coverage for edit_file_name function modifications and custom_404_handler changes central to fixing issue #11458. Add unit tests for edit_file_name, integration tests for custom_404_handler, enhance existing test validation, and verify issue #11458 end-to-end behavior.
Test File Naming And Structure ⚠️ Warning PR modifies three source files but only updates tests for one. Missing test coverage for edit_file_name endpoint in files.py and custom_404_handler in main.py. Add test files for api/v2/files.py and integration tests for main.py custom_404_handler to achieve complete test coverage of all modified functionality.
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main fix: API endpoints now return JSON 404 responses instead of HTML when resources are not found, which matches the core changes across multiple files.
Linked Issues check ✅ Passed The PR addresses the core requirement from issue #11458: preventing the SPA handler from intercepting API 404s and ensuring API endpoints return 404 JSON responses. The changes to the 404 handler, variable.py, and files.py directly implement the fixes described.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing API 404 responses: the main.py handler re-raises API 404s, variable.py and files.py add proper 404 handling, and tests verify the expected behavior. No unrelated changes detected.
Test Coverage For New Implementations ✅ Passed The PR includes comprehensive test coverage validating 404 responses for non-existent resources, including test_delete_variable__exception and test_download_file_not_found with assertions on HTTP status codes.
Excessive Mock Usage Warning ✅ Passed Test file uses real fixtures and dependencies without excessive mocking. Only assertion status code changed from 500 to 404 to match updated error handling behavior.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 27, 2026
@AntonioABLima AntonioABLima force-pushed the fix/api-404-json-response branch from e54a6da to ac800a6 Compare January 28, 2026 01:52
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetProject endpoint returns 200 with HTML instead of 404 for non-existent projects

1 participant