Skip to content
Snippets Groups Projects
Verified Commit 0cbf9001 authored by Nik | Klampfradler's avatar Nik | Klampfradler Committed by Jonathan Weth
Browse files

Make 5xx errors work again

(cherry picked from commit f9852851)
parent 48eee97c
No related branches found
No related tags found
1 merge request!697Prepare release 2.0rc4
......@@ -19,6 +19,7 @@ Fixed
* Use text HTTP response for serviceworker.js insteas of binary stream
* Use Django permission instead of rule to prevent performance issues.
* Correctly deliver server errors to user
`2.0rc3`_ - 2021-07-26
----------------------
......
......@@ -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:
"""Custom error view that ensures 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