Skip to content

Saleor Core: the high performance, composable, headless commerce API.

GraphQL now prints exceptions to stderr as well as returning them or not

NyanKiyoshifc18db2b20bb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 290683e0c7..d9bb82c923 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Add support for Google Cloud Storage - #4127 by @chetabahana
- Fix wrong calculation of subtotal in cart page - #4145 by @korycins
- Fix multiple checkbox selected behavior - #4146 by @benekex2
+- GraphQL now prints exceptions to stderr as well as returning them or not - #4148 by @NyanKiyoshi
## 2.6.0
diff --git a/saleor/graphql/views.py b/saleor/graphql/views.py
index 2de768e297..564fa33c0b 100644
--- a/saleor/graphql/views.py
+++ b/saleor/graphql/views.py
@@ -1,4 +1,5 @@
import json
+import logging
import traceback
from django.conf import settings
@@ -15,6 +16,8 @@ from graphql.error import (
)
from graphql.execution import ExecutionResult
+logger = logging.getLogger(__name__)
+
class GraphQLView(View):
# This class is our implementation of `graphene_django.views.GraphQLView`,
@@ -190,10 +193,14 @@ class GraphQLView(View):
result = format_graphql_error(error)
else:
result = {"message": str(error)}
+
+ exc = error
+ while isinstance(exc, GraphQLError) and hasattr(exc, "original_error"):
+ exc = exc.original_error
+
+ logger.error("Exception information:", exc_info=exc)
+
if settings.DEBUG:
- exc = error
- while isinstance(exc, GraphQLError) and hasattr(exc, "original_error"):
- exc = exc.original_error
lines = []
for line in traceback.format_exception(type(exc), exc, exc.__traceback__):
lines.extend(line.rstrip().splitlines())