Skip to content

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

Add error code to failed response

Maciej Korycinski686bc5a28661
diff --git a/saleor/graphql/views.py b/saleor/graphql/views.py
index f462e56531..3923b6efc1 100644
--- a/saleor/graphql/views.py
+++ b/saleor/graphql/views.py
@@ -200,6 +200,7 @@ class GraphQLView(View):
logger.error("Exception information:", exc_info=exc)
+ result["extensions"] = {"exception": {"code": type(exc).__name__}}
if settings.DEBUG:
lines = []
@@ -208,10 +209,7 @@ class GraphQLView(View):
type(exc), exc, exc.__traceback__
):
lines.extend(line.rstrip().splitlines())
-
- result["extensions"] = {
- "exception": {"code": type(exc).__name__, "stacktrace ": lines}
- }
+ result["extensions"]["exception"]["stacktrace"] = lines
return result
diff --git a/tests/api/test_view.py b/tests/api/test_view.py
index 4ee81f7968..a6aecc9d80 100644
--- a/tests/api/test_view.py
+++ b/tests/api/test_view.py
@@ -87,7 +87,7 @@ def test_invalid_request_body_with_debug(client):
errors = content.get("errors")
assert errors == [
{
- "extensions": {"exception": {"code": "str", "stacktrace ": []}},
+ "extensions": {"exception": {"code": "str", "stacktrace": []}},
"message": "Unable to parse query.",
}
]