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):
|
def handle(self, *args, **options):
|
||||||
size = options["size"]
|
size = options["size"]
|
||||||
while True:
|
while True:
|
||||||
batch_ids = list(
|
batch_ids = list(Product.objects.filter(orderproduct__isnull=True).values_list("pk", flat=True)[:size])
|
||||||
Product.objects.filter(orderproduct__isnull=True).values_list("pk", flat=True)[:size]
|
|
||||||
)
|
|
||||||
if not batch_ids:
|
if not batch_ids:
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from os import getenv
|
||||||
|
|
||||||
from constance import config
|
from constance import config
|
||||||
from django.contrib.auth.models import AnonymousUser
|
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.http import HttpResponseForbidden
|
||||||
from django.middleware.common import CommonMiddleware
|
from django.middleware.common import CommonMiddleware
|
||||||
from django.middleware.locale import LocaleMiddleware
|
from django.middleware.locale import LocaleMiddleware
|
||||||
|
|
@ -95,12 +95,20 @@ class BlockInvalidHostMiddleware:
|
||||||
|
|
||||||
# noinspection PyShadowingBuiltins
|
# noinspection PyShadowingBuiltins
|
||||||
class GrapheneLoggingErrorsDebugMiddleware:
|
class GrapheneLoggingErrorsDebugMiddleware:
|
||||||
|
WARNING_ONLY_ERRORS = [
|
||||||
|
BadRequest,
|
||||||
|
PermissionDenied,
|
||||||
|
DisallowedHost,
|
||||||
|
ValidationError,
|
||||||
|
]
|
||||||
|
|
||||||
def resolve(self, next, root, info, **args):
|
def resolve(self, next, root, info, **args):
|
||||||
try:
|
try:
|
||||||
return next(root, info, **args)
|
return next(root, info, **args)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Error occurred in GraphQL execution:", exc_info=True)
|
if e in self.WARNING_ONLY_ERRORS:
|
||||||
if bool(int(getenv("DEBUG"))):
|
logger.warning(str(e))
|
||||||
|
else:
|
||||||
logger.error(str(e))
|
logger.error(str(e))
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
capture_exception(e)
|
capture_exception(e)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue