Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion inertia/http.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from functools import wraps
from http import HTTPStatus
from json import dumps as json_encode
Expand All @@ -18,6 +19,7 @@
except ImportError:
requests = None # type: ignore[assignment]

logger = logging.getLogger(__name__)

INERTIA_REQUEST_ENCRYPT_HISTORY = "_inertia_encrypt_history"
INERTIA_SESSION_CLEAR_HISTORY = "_inertia_clear_history"
Expand Down Expand Up @@ -172,7 +174,7 @@ def build_first_load_context_and_template(
**self.template_data,
}, INERTIA_SSR_TEMPLATE
except Exception:
pass
logger.exception("SSR render request failed")

return {
"page": data,
Expand Down
15 changes: 14 additions & 1 deletion inertia/tests/test_ssr.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_it_uses_inertia_if_inertia_requests_are_made(self, mock_requests):
@patch("inertia.http.requests")
def test_it_fallsback_on_failure(self, mock_requests):
def uh_oh(*args, **kwargs):
raise ValueError() # all exceptions are caught and ignored
raise ValueError() # SSR errors are logged and fall back to client-side rendering

mock_response = Mock()
mock_response.raise_for_status.side_effect = uh_oh
Expand All @@ -75,3 +75,16 @@ def uh_oh(*args, **kwargs):
self.assertContains(
response, inertia_div("props", props={"name": "Brandon", "sport": "Hockey"})
)

@patch("inertia.http.logger")
@patch("inertia.http.requests")
def test_it_logs_exception_on_ssr_failure(self, mock_requests, mock_logger):
error = ValueError("SSR rendering failed")

mock_response = Mock()
mock_response.raise_for_status.side_effect = error
mock_requests.post.return_value = mock_response

self.client.get("/props/")

mock_logger.exception.assert_called_once_with("SSR render request failed")
Comment on lines +79 to +90
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test verifies that logging occurs but doesn't validate that the fallback behavior still works correctly. Consider asserting that the response contains the expected client-side rendering content (similar to line 75-77 in test_it_fallsback_on_failure) to ensure both logging and graceful degradation work together.

Copilot uses AI. Check for mistakes.
Loading