Features: 1) Introduced distinct warning and error logging for specific exceptions in GraphQL middleware; 2) Added new exception types for enhanced validation handling.
Fixes: 1) Corrected indentation inconsistency in delete_never_ordered_products command; 2) Fixed improper formatting of log handler configurations. Extra: Adjusted logging to conform to best practices; amended middleware exception handling logic to improve code readability.
This commit is contained in:
parent
4ef06dd971
commit
a562591900
3 changed files with 22 additions and 16 deletions
|
|
@ -18,9 +18,7 @@ class Command(BaseCommand):
|
|||
def handle(self, *args, **options):
|
||||
size = options["size"]
|
||||
while True:
|
||||
batch_ids = list(
|
||||
Product.objects.filter(orderproduct__isnull=True).values_list("pk", flat=True)[:size]
|
||||
)
|
||||
batch_ids = list(Product.objects.filter(orderproduct__isnull=True).values_list("pk", flat=True)[:size])
|
||||
if not batch_ids:
|
||||
break
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from os import getenv
|
|||
|
||||
from constance import config
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.core.exceptions import BadRequest, DisallowedHost
|
||||
from django.core.exceptions import BadRequest, DisallowedHost, PermissionDenied, ValidationError
|
||||
from django.http import HttpResponseForbidden
|
||||
from django.middleware.common import CommonMiddleware
|
||||
from django.middleware.locale import LocaleMiddleware
|
||||
|
|
@ -95,12 +95,20 @@ class BlockInvalidHostMiddleware:
|
|||
|
||||
# noinspection PyShadowingBuiltins
|
||||
class GrapheneLoggingErrorsDebugMiddleware:
|
||||
WARNING_ONLY_ERRORS = [
|
||||
BadRequest,
|
||||
PermissionDenied,
|
||||
DisallowedHost,
|
||||
ValidationError,
|
||||
]
|
||||
|
||||
def resolve(self, next, root, info, **args):
|
||||
try:
|
||||
return next(root, info, **args)
|
||||
except Exception as e:
|
||||
logger.error("Error occurred in GraphQL execution:", exc_info=True)
|
||||
if bool(int(getenv("DEBUG"))):
|
||||
if e in self.WARNING_ONLY_ERRORS:
|
||||
logger.warning(str(e))
|
||||
else:
|
||||
logger.error(str(e))
|
||||
logger.error(traceback.format_exc())
|
||||
capture_exception(e)
|
||||
|
|
|
|||
Loading…
Reference in a new issue