2020-01-21 06:35:58 +00:00
|
|
|
import traceback
|
|
|
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
from django.utils.translation import gettext as _
|
|
|
|
|
|
|
|
|
|
|
|
def error(request, context, status):
|
2022-05-14 17:57:27 +00:00
|
|
|
return render(request, "error.html", context=context, status=status)
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def error404(request, exception=None):
|
|
|
|
# TODO: "panic: go back"
|
2022-05-14 17:57:27 +00:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"generic-message.html",
|
|
|
|
{
|
|
|
|
"title": _("404 error"),
|
|
|
|
"message": _('Could not find page "%s"') % request.path,
|
|
|
|
},
|
|
|
|
status=404,
|
|
|
|
)
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def error403(request, exception=None):
|
2022-05-14 17:57:27 +00:00
|
|
|
return error(
|
|
|
|
request,
|
|
|
|
{
|
|
|
|
"id": "unauthorized_access",
|
|
|
|
"description": _("no permission for %s") % request.path,
|
|
|
|
"code": 403,
|
|
|
|
},
|
|
|
|
403,
|
|
|
|
)
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def error500(request):
|
2022-05-14 17:57:27 +00:00
|
|
|
return error(
|
|
|
|
request,
|
|
|
|
{
|
|
|
|
"id": "invalid_state",
|
|
|
|
"description": _("corrupt page %s") % request.path,
|
|
|
|
"traceback": traceback.format_exc(),
|
|
|
|
"code": 500,
|
|
|
|
},
|
|
|
|
500,
|
|
|
|
)
|