Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Map assertion and value error to graphql error (#7289)
Damian Wysocki97c9d603cdb0
diff --git a/saleor/graphql/core/tests/test_view.py b/saleor/graphql/core/tests/test_view.pyindex c3c38b4c67..56acba2245 100644--- a/saleor/graphql/core/tests/test_view.py+++ b/saleor/graphql/core/tests/test_view.py@@ -64,6 +64,28 @@ def test_batch_queries(category, product, api_client, channel_USD):assert data["category"]["name"] == category.name+def test_graphql_view_query_with_invalid_object_type(+ staff_api_client, product, permission_manage_orders, graphql_log_handler+):+ query = """+ query($id: ID!) {+ order(id: $id){+ token+ }+ }+ """+ variables = {+ "id": graphene.Node.to_global_id("Product", product.pk),+ }+ staff_api_client.user.user_permissions.add(permission_manage_orders)+ response = staff_api_client.post_graphql(query, variables=variables)++ assert response.status_code == 200+ assert graphql_log_handler.messages == [+ "saleor.graphql.errors.handled[INFO].GraphQLError"+ ]++@pytest.mark.parametrize("playground_on, status", [(True, 200), (False, 405)])def test_graphql_view_get_enabled_or_disabled(client, settings, playground_on, status):settings.PLAYGROUND_ENABLED = playground_ondiff --git a/saleor/graphql/views.py b/saleor/graphql/views.pyindex 91e4574e3c..6c901dfdd2 100644--- a/saleor/graphql/views.py+++ b/saleor/graphql/views.py@@ -295,7 +295,7 @@ class GraphQLView(View):# In the graphql-core version that we are using,# the Exception is raised for too big integers value.# As it's a validation error we want to raise GraphQLError instead.- if str(e).startswith(INT_ERROR_MSG):+ if str(e).startswith(INT_ERROR_MSG) or isinstance(e, ValueError):e = GraphQLError(str(e))return ExecutionResult(errors=[e], invalid=True)@@ -341,7 +341,8 @@ class GraphQLView(View):exc = errorwhile isinstance(exc, GraphQLError) and hasattr(exc, "original_error"):exc = exc.original_error-+ if isinstance(exc, AssertionError):+ exc = GraphQLError(str(exc))if isinstance(exc, cls.HANDLED_EXCEPTIONS):handled_errors_logger.info("A query had an error", exc_info=exc)else: