Browse Source

feat(api): don't send email for database IntegrityError

Those occur rather frequently when there's a race between two requests such
that serializer validation doesn't see the conflicting record, but database
constraints then fail. Observation of 120 such cases over three years has
not revealed anything that would need fixing.
Peter Thomassen 1 year ago
parent
commit
aa948f9151
1 changed files with 2 additions and 2 deletions
  1. 2 2
      api/desecapi/exception_handlers.py

+ 2 - 2
api/desecapi/exception_handlers.py

@@ -28,12 +28,14 @@ def exception_handler(exc, context):
         return Response({"detail": f"Conflict: {exc}"}, status=status.HTTP_409_CONFLICT)
         return Response({"detail": f"Conflict: {exc}"}, status=status.HTTP_409_CONFLICT)
 
 
     def _500():
     def _500():
+        _log()
         return Response(
         return Response(
             {"detail": "Internal Server Error. We're on it!"},
             {"detail": "Internal Server Error. We're on it!"},
             status=status.HTTP_500_INTERNAL_SERVER_ERROR,
             status=status.HTTP_500_INTERNAL_SERVER_ERROR,
         )
         )
 
 
     def _503():
     def _503():
+        _log()
         return Response(
         return Response(
             {"detail": "Please try again later."},
             {"detail": "Please try again later."},
             status=status.HTTP_503_SERVICE_UNAVAILABLE,
             status=status.HTTP_503_SERVICE_UNAVAILABLE,
@@ -54,7 +56,6 @@ def exception_handler(exc, context):
             2026,  # SSL connection error
             2026,  # SSL connection error
         )
         )
     ):
     ):
-        _log()
         metrics.get("desecapi_database_unavailable").inc()
         metrics.get("desecapi_database_unavailable").inc()
         return _503()
         return _503()
 
 
@@ -66,7 +67,6 @@ def exception_handler(exc, context):
 
 
     for exception_class, handler in handlers.items():
     for exception_class, handler in handlers.items():
         if isinstance(exc, exception_class):
         if isinstance(exc, exception_class):
-            _log()
             # TODO add metrics
             # TODO add metrics
             return handler()
             return handler()