mirror of
https://github.com/inventree/InvenTree.git
synced 2026-08-13 00:46:15 +00:00
Fix for API exception_handler (#12604)
- Only log unhandled exceptions to sentry.io - Check for valid handling first - Report second
This commit is contained in:
@@ -115,13 +115,6 @@ def exception_handler(exc, context):
|
||||
|
||||
response = None
|
||||
|
||||
# Pass exception to sentry.io handler
|
||||
try:
|
||||
InvenTree.sentry.report_exception(exc)
|
||||
except Exception:
|
||||
# If sentry.io fails, we don't want to crash the server!
|
||||
pass
|
||||
|
||||
# The Django app registry can be transiently un-ready while the plugin
|
||||
# registry is reloading apps (see plugin.registry.PluginsRegistry._reload_apps).
|
||||
# Any request handled by another thread/worker during that window can trip
|
||||
@@ -141,9 +134,17 @@ def exception_handler(exc, context):
|
||||
return response
|
||||
|
||||
# Catch any django validation error, and re-throw a DRF validation error
|
||||
if isinstance(exc, DjangoValidationError):
|
||||
elif isinstance(exc, DjangoValidationError):
|
||||
exc = DRFValidationError(detail=serializers.as_serializer_error(exc))
|
||||
|
||||
else:
|
||||
# Pass any other (unhandled) exception to sentry.io handler
|
||||
try:
|
||||
InvenTree.sentry.report_exception(exc)
|
||||
except Exception:
|
||||
# If sentry.io fails, we don't want to crash the server!
|
||||
pass
|
||||
|
||||
# Default to the built-in DRF exception handler
|
||||
response = drfviews.exception_handler(exc, context)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user