mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Merged release v2.3.7
This commit is contained in:
@ -5,9 +5,10 @@ import sys
|
||||
from django.conf import settings
|
||||
from django.db import ProgrammingError
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
|
||||
from .views import server_error
|
||||
|
||||
BASE_PATH = getattr(settings, 'BASE_PATH', False)
|
||||
LOGIN_REQUIRED = getattr(settings, 'LOGIN_REQUIRED', False)
|
||||
|
||||
@ -65,23 +66,19 @@ class ExceptionHandlingMiddleware(object):
|
||||
if isinstance(exception, Http404):
|
||||
return
|
||||
|
||||
# Determine the type of exception
|
||||
# Determine the type of exception. If it's a common issue, return a custom error page with instructions.
|
||||
custom_template = None
|
||||
if isinstance(exception, ProgrammingError):
|
||||
template_name = 'exceptions/programming_error.html'
|
||||
custom_template = 'exceptions/programming_error.html'
|
||||
elif isinstance(exception, ImportError):
|
||||
template_name = 'exceptions/import_error.html'
|
||||
custom_template = 'exceptions/import_error.html'
|
||||
elif (
|
||||
sys.version_info[0] >= 3 and isinstance(exception, PermissionError)
|
||||
) or (
|
||||
isinstance(exception, OSError) and exception.errno == 13
|
||||
):
|
||||
template_name = 'exceptions/permission_error.html'
|
||||
else:
|
||||
template_name = '500.html'
|
||||
custom_template = 'exceptions/permission_error.html'
|
||||
|
||||
# Return an error message
|
||||
type_, error, traceback = sys.exc_info()
|
||||
return render(request, template_name, {
|
||||
'exception': str(type_),
|
||||
'error': error,
|
||||
}, status=500)
|
||||
# Return a custom error message, or fall back to Django's default 500 error handling
|
||||
if custom_template:
|
||||
return server_error(request, template_name=custom_template)
|
||||
|
Reference in New Issue
Block a user