Skip to content

Commit

Permalink
Merge pull request #35259 from raccoongang/max/backport-error-page-re…
Browse files Browse the repository at this point in the history
…nder-recurse

[Backport] fix: Prevent error page recursion (#35209)
  • Loading branch information
cmltaWt0 authored Aug 8, 2024
2 parents d5c84e9 + fa97f13 commit 3d50dd8
Showing 1 changed file with 21 additions and 2 deletions.
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.")

0 comments on commit 3d50dd8

Please sign in to comment.