Skip to content
Snippets Groups Projects
Commit fc42dfb4 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Merge branch '494-error-in-5xx-pages' into 'master'

Resolve "Error in 5xx pages"

Closes #494

See merge request AlekSIS/official/AlekSIS-Core!696
parents fb4dff70 ddf5e38c
No related branches found
No related tags found
1 merge request!696Resolve "Error in 5xx pages"
Pipeline #25148 failed
......@@ -17,6 +17,7 @@ Added
Fixed
~~~~~
* Correctly deliver server errors to user
* Use text HTTP response for serviceworker.js insteas of binary stream
`2.0rc3`_ - 2021-07-26
......
......@@ -6,7 +6,7 @@
<div class="container">
<div class="card red">
<div class="card-content white-text">
<div class="material-icons small left">error_outline</div>
<i class="material-icons small left">error_outline</i>
<span class="card-title">{% trans "Error" %} (500): {% blocktrans %}An unexpected error has
occured.{% endblocktrans %}</span>
<p>
......
......@@ -6,7 +6,7 @@
<div class="container">
<div class="card red">
<div class="card-content white-text">
<div class="material-icons small left">error_outline</div>
<i class="material-icons small left">error_outline</i>
<span class="card-title">{% blocktrans %}The maintenance mode is currently enabled. Please try again
later.{% endblocktrans %}</span>
<p>
......
......@@ -226,6 +226,9 @@ urlpatterns = [
path("pdfs/<int:pk>/", views.RedirectToPDFFile.as_view(), name="redirect_to_pdf_file"),
]
# Use custom server error handler to get a request object in the template
handler500 = views.server_error
# Add URLs for optional features
if hasattr(settings, "TWILIO_ACCOUNT_SID"):
from two_factor.gateways.twilio.urls import urlpatterns as tf_twilio_urls # noqa
......
......@@ -13,14 +13,17 @@ from django.http import (
HttpResponse,
HttpResponseNotFound,
HttpResponseRedirect,
HttpResponseServerError,
JsonResponse,
)
from django.shortcuts import get_object_or_404, redirect, render
from django.template import loader
from django.urls import reverse, reverse_lazy
from django.utils.decorators import method_decorator
from django.utils.translation import get_language
from django.utils.translation import gettext_lazy as _
from django.views.decorators.cache import never_cache
from django.views.defaults import ERROR_500_TEMPLATE_NAME
from django.views.generic.base import TemplateView, View
from django.views.generic.detail import DetailView, SingleObjectMixin
from django.views.generic.edit import DeleteView, UpdateView
......@@ -1199,3 +1202,13 @@ class SocialAccountDeleteView(DeleteView):
self.request, _("The third-party account has been successfully disconnected.")
)
return HttpResponseRedirect(success_url)
def server_error(
request: HttpRequest, template_name: str = ERROR_500_TEMPLATE_NAME
) -> HttpResponseServerError:
"""Ensure the request is passed to the error page."""
template = loader.get_template(template_name)
context = {"request": request}
return HttpResponseServerError(template.render(context))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment