-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add global exception handling and custom 503 error page
- Loading branch information
1 parent
70f990f
commit 9dbb4ae
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="pt-br"> | ||
<head> | ||
<title>Toolforge Database Error - WikiScore</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" href="/static/w3.css"> | ||
<link href="https://tools-static.wmflabs.org/fontcdn/css?family=Roboto" rel="stylesheet" type="text/css"> | ||
</head> | ||
<body style="font-family: 'Roboto', sans-serif;"> | ||
|
||
<!-- Header --> | ||
<header class="w3-container w3-content w3-padding-32 w3-center"> | ||
<img alt="logo" src="/static/Logo_Preto_Tagline.svg" style="width: 300px;"> | ||
<h1 class="w3-jumbo w3-text-red">Toolforge Database Error</h1> | ||
<p class="w3-xlarge">We encountered a database connection issue with Toolforge.</p> | ||
<p class="w3-xlarge">This is a temporary issue with Toolforge's database infrastructure and not a problem with our service.</p> | ||
<p class="w3-xlarge">Please try again in a few minutes. We apologize for the inconvenience.</p> | ||
<button class="w3-button w3-black w3-padding w3-margin-top w3-round-xxlarge" onclick="location.href='/'">Return to homepage</button> | ||
</header> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters