mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
SSO Error Improvememts (#6246)
* Improve exception handling * Extract extra information from SSO auth failure * Revert order of ignore check
This commit is contained in:
parent
4b5fcd4e69
commit
428a4c0386
@ -23,13 +23,18 @@ import InvenTree.sentry
|
|||||||
logger = logging.getLogger('inventree')
|
logger = logging.getLogger('inventree')
|
||||||
|
|
||||||
|
|
||||||
def log_error(path):
|
def log_error(path, error_name=None, error_info=None, error_data=None):
|
||||||
"""Log an error to the database.
|
"""Log an error to the database.
|
||||||
|
|
||||||
- Uses python exception handling to extract error details
|
- Uses python exception handling to extract error details
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
path: The 'path' (most likely a URL) associated with this error (optional)
|
path: The 'path' (most likely a URL) associated with this error (optional)
|
||||||
|
|
||||||
|
kwargs:
|
||||||
|
error_name: The name of the error (optional, overrides 'kind')
|
||||||
|
error_info: The error information (optional, overrides 'info')
|
||||||
|
error_data: The error data (optional, overrides 'data')
|
||||||
"""
|
"""
|
||||||
kind, info, data = sys.exc_info()
|
kind, info, data = sys.exc_info()
|
||||||
|
|
||||||
@ -37,19 +42,31 @@ def log_error(path):
|
|||||||
if kind in settings.IGNORED_ERRORS:
|
if kind in settings.IGNORED_ERRORS:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if error_name:
|
||||||
|
kind = error_name
|
||||||
|
else:
|
||||||
|
kind = getattr(kind, '__name__', 'Unknown Error')
|
||||||
|
|
||||||
|
if error_info:
|
||||||
|
info = error_info
|
||||||
|
|
||||||
|
if error_data:
|
||||||
|
data = error_data
|
||||||
|
else:
|
||||||
|
data = '\n'.join(traceback.format_exception(kind, info, data))
|
||||||
|
|
||||||
# Log error to stderr
|
# Log error to stderr
|
||||||
logger.error(info)
|
logger.error(info)
|
||||||
|
|
||||||
|
# Ensure the error information does not exceed field size limits
|
||||||
|
path = path[:200]
|
||||||
|
kind = kind[:128]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Error.objects.create(
|
Error.objects.create(kind=kind, info=info or '', data=data or '', path=path)
|
||||||
kind=kind.__name__,
|
except Exception:
|
||||||
info=info,
|
|
||||||
data='\n'.join(traceback.format_exception(kind, info, data)),
|
|
||||||
path=path,
|
|
||||||
)
|
|
||||||
except (OperationalError, IntegrityError):
|
|
||||||
# Not much we can do if logging the error throws a db exception
|
# Not much we can do if logging the error throws a db exception
|
||||||
pass
|
logger.exception('Failed to log exception to database')
|
||||||
|
|
||||||
|
|
||||||
def exception_handler(exc, context):
|
def exception_handler(exc, context):
|
||||||
|
@ -363,8 +363,16 @@ class CustomSocialAccountAdapter(
|
|||||||
self, request, provider_id, error=None, exception=None, extra_context=None
|
self, request, provider_id, error=None, exception=None, extra_context=None
|
||||||
):
|
):
|
||||||
"""Callback method for authentication errors."""
|
"""Callback method for authentication errors."""
|
||||||
|
if not error:
|
||||||
|
error = request.GET.get('error', None)
|
||||||
|
|
||||||
|
if not exception:
|
||||||
|
exception = request.GET.get('error_description', None)
|
||||||
|
|
||||||
|
path = request.path or 'sso'
|
||||||
|
|
||||||
# Log the error to the database
|
# Log the error to the database
|
||||||
log_error(request.path if request else 'sso')
|
log_error(path, error_name=error, error_data=exception)
|
||||||
logger.error("SSO error for provider '%s' - check admin error log", provider_id)
|
logger.error("SSO error for provider '%s' - check admin error log", provider_id)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user