middleware: Handle OperationalErrors
For #1443 (closed).
- CommonErrorMiddleware with custom 503 template implemented by @pancrypticon-guest at pancrypticon-guest/plinth@master...dblock.
- Added unit test.
- Tested using a temporary view with following test code:
diff --git a/plinth/urls.py b/plinth/urls.py
index 34c61068c..c81152c95 100644
--- a/plinth/urls.py
+++ b/plinth/urls.py
@@ -32,5 +32,7 @@ urlpatterns = [
# Notifications
re_path(r'^notification/(?P<id>[A-Za-z0-9-=]+)/dismiss/$',
- views.notification_dismiss, name='notification_dismiss')
+ views.notification_dismiss, name='notification_dismiss'),
+
+ re_path(r'^operror/$', views.operror, name='operror')
]
diff --git a/plinth/views.py b/plinth/views.py
index 8cb5d4c20..499f56cd7 100644
--- a/plinth/views.py
+++ b/plinth/views.py
@@ -9,6 +9,7 @@ import urllib.parse
from django.contrib import messages
from django.core.exceptions import ImproperlyConfigured
+from django.db.utils import OperationalError
from django.http import Http404, HttpResponseBadRequest, HttpResponseRedirect
from django.shortcuts import redirect
from django.template.response import TemplateResponse
@@ -495,3 +496,7 @@ def notification_dismiss(request, id):
notes[0].dismiss()
return HttpResponseRedirect(_get_redirect_url_from_param(request))
+
+
+def operror(request):
+ raise OperationalError()