Skip to content

Commit

Permalink
Skip internal Django exception for 4XX responses in ErrorLoggingMiddl…
Browse files Browse the repository at this point in the history
…eware

Fix #17
  • Loading branch information
browniebroke authored and lnagel committed Jan 20, 2024
1 parent de99f74 commit ae8fe28
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions django_datadog_logger/middleware/error_log.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import logging

from django.core.exceptions import PermissionDenied, BadRequest, SuspiciousOperation
from django.http import Http404
from django.http.multipartparser import MultiPartParserError

logger = logging.getLogger(__name__)

Expand All @@ -12,6 +15,11 @@ def __call__(self, request):
return self.get_response(request)

def process_exception(self, request, exception):
if isinstance(
exception,
(PermissionDenied, Http404, MultiPartParserError, BadRequest, SuspiciousOperation),
):
return
logger.exception(exception)

def process_response(self, request, response):
Expand Down

0 comments on commit ae8fe28

Please sign in to comment.