diff --git a/templates/503.html b/templates/503.html
new file mode 100644
index 0000000..e01af86
--- /dev/null
+++ b/templates/503.html
@@ -0,0 +1,23 @@
+
+
+
+
+
+ Toolforge Database Error
+ We encountered a database connection issue with Toolforge.
+ This is a temporary issue with Toolforge's database infrastructure and not a problem with our service.
+ Please try again in a few minutes. We apologize for the inconvenience.
+
+
+
+
+
diff --git a/wikiscore/middleware.py b/wikiscore/middleware.py
new file mode 100644
index 0000000..7cffbe0
--- /dev/null
+++ b/wikiscore/middleware.py
@@ -0,0 +1,19 @@
+from django.shortcuts import render
+import traceback
+
+class GlobalExceptionMiddleware:
+ def __init__(self, get_response):
+ self.get_response = get_response
+
+ def __call__(self, request):
+ try:
+ response = self.get_response(request)
+ return response
+ except AttributeError as e:
+ tb = traceback.format_exc()
+ if "'NoneType' object has no attribute 'settimeout'" in str(e) and "pymysql" in tb:
+ # Return a 503 Service Unavailable response
+ response = render(request, '503.html', status=503)
+ else:
+ raise
+ return response
diff --git a/wikiscore/settings.py b/wikiscore/settings.py
index 4152549..581b7ec 100644
--- a/wikiscore/settings.py
+++ b/wikiscore/settings.py
@@ -53,6 +53,7 @@
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware',
+ 'wikiscore.middleware.GlobalExceptionMiddleware',
]
ROOT_URLCONF = 'wikiscore.urls'