generated from opensafely-core/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Each of Django's handlers wraps the generic error() view since all we really want in this application is a page saying something has gone wrong.
- Loading branch information
Showing
10 changed files
with
145 additions
and
2 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 @@ | ||
import "../styles/error.css"; |
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,9 @@ | ||
body { | ||
grid-template-rows: 1fr max-content 1fr; | ||
grid-template-columns: 1fr; | ||
} | ||
|
||
body > div { | ||
grid-template-rows: 1fr; | ||
grid-template-columns: 1fr min-content 1fr; | ||
} |
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
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,31 @@ | ||
from django.template.response import TemplateResponse | ||
|
||
|
||
def error(request, *, status=500, message=""): | ||
"""Generic error view""" | ||
return TemplateResponse( | ||
request, | ||
"error.html", | ||
status=status, | ||
context={"message": message}, | ||
) | ||
|
||
|
||
def bad_request(request, exception=None): | ||
return error(request, status=400) | ||
|
||
|
||
def csrf_failure(request, reason=""): | ||
return error(request, status=400) | ||
|
||
|
||
def page_not_found(request, exception=None): | ||
return error(request, status=404) | ||
|
||
|
||
def permission_denied(request, exception=None): | ||
return error(request, status=403) | ||
|
||
|
||
def server_error(request): | ||
return error(request) |
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
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,33 @@ | ||
{% load django_vite %} | ||
|
||
<!DOCTYPE html> | ||
<html lang="en" class="min-h-screen"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<title>SACRO Outputs Viewer</title> | ||
|
||
{% vite_hmr_client %} | ||
{% vite_asset "assets/src/scripts/base.js" %} | ||
{% vite_asset "assets/src/scripts/error.js" %} | ||
</head> | ||
|
||
<body class="grid h-screen"> | ||
<div class="row-start-2 grid"> | ||
<div class="col-start-2 flex flex-col gap-3 text-center w-screen"> | ||
<div class="flex justify-center"> | ||
{% icon_exclamation_triangle class="h-32 w-32 stroke-slate-700" %} | ||
</div> | ||
|
||
<p class="break-normal"> | ||
The application encourtered a problem. Please restart the application and try | ||
again. If this problem continues please contact support. | ||
</p> | ||
|
||
<p class="break-words">{{ message }}</p> | ||
</div> | ||
</div> | ||
|
||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,57 @@ | ||
from sacro.errors import ( | ||
bad_request, | ||
csrf_failure, | ||
error, | ||
page_not_found, | ||
permission_denied, | ||
server_error, | ||
) | ||
|
||
|
||
def test_bad_request(rf): | ||
request = rf.get("/") | ||
|
||
response = bad_request(request) | ||
|
||
assert response.status_code == 400 | ||
|
||
|
||
def test_csrf_failure(rf): | ||
request = rf.get("/") | ||
|
||
response = csrf_failure(request) | ||
|
||
assert response.status_code == 400 | ||
|
||
|
||
def test_error_with_message(rf): | ||
request = rf.get("/") | ||
|
||
response = error(request, message="testing") | ||
|
||
assert response.status_code == 500 | ||
assert "testing" in response.rendered_content | ||
|
||
|
||
def test_permission_denied(rf): | ||
request = rf.get("/") | ||
|
||
response = permission_denied(request) | ||
|
||
assert response.status_code == 403 | ||
|
||
|
||
def test_page_not_found(rf): | ||
request = rf.get("/") | ||
|
||
response = page_not_found(request) | ||
|
||
assert response.status_code == 404 | ||
|
||
|
||
def test_server_error(rf): | ||
request = rf.get("/") | ||
|
||
response = server_error(request) | ||
|
||
assert response.status_code == 500 |
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