Skip to content
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

fix: Prevent error page recursion #35209

Merged
merged 1 commit into from
Jul 31, 2024
Merged
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
23 changes: 21 additions & 2 deletions lms/djangoapps/static_template_view/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# List of valid templates is explicitly managed for (short-term)
# security reasons.


import logging
import mimetypes

from django.conf import settings
Expand All @@ -23,6 +23,8 @@
from common.djangoapps.util.views import fix_crum_request
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers

log = logging.getLogger(__name__)

valid_templates = []

if settings.STATIC_GRAB:
Expand Down Expand Up @@ -122,4 +124,21 @@ def render_429(request, exception=None): # lint-amnesty, pylint: disable=unused

@fix_crum_request
def render_500(request):
return HttpResponseServerError(render_to_string('static_templates/server-error.html', {}, request=request))
"""
Render the generic error page when we have an uncaught error.
"""
try:
return HttpResponseServerError(render_to_string('static_templates/server-error.html', {}, request=request))
except BaseException as e:
# If we can't render the error page, ensure we don't raise another
# exception -- because if we do, we'll probably just end up back
# at the same rendering error.
#
# This is an attempt at working around the recursive error handling issues
# observed in <https://github.com/openedx/edx-platform/issues/35151>, which
# were triggered by Mako and translation errors.

log.error("Encountered error while rendering error page.", exc_info=True)
# This message is intentionally hardcoded and does not involve
# any translation, templating, etc. Do not translate.
return HttpResponseServerError("Encountered error while rendering error page.")
Loading