浏览代码

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 年之前
父节点
当前提交
aa948f9151
共有 1 个文件被更改,包括 2 次插入2 次删除
  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)
 
     def _500():
+        _log()
         return Response(
             {"detail": "Internal Server Error. We're on it!"},
             status=status.HTTP_500_INTERNAL_SERVER_ERROR,
         )
 
     def _503():
+        _log()
         return Response(
             {"detail": "Please try again later."},
             status=status.HTTP_503_SERVICE_UNAVAILABLE,
@@ -54,7 +56,6 @@ def exception_handler(exc, context):
             2026,  # SSL connection error
         )
     ):
-        _log()
         metrics.get("desecapi_database_unavailable").inc()
         return _503()
 
@@ -66,7 +67,6 @@ def exception_handler(exc, context):
 
     for exception_class, handler in handlers.items():
         if isinstance(exc, exception_class):
-            _log()
             # TODO add metrics
             return handler()