Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use more specific error class
Marcin Gębalad5f92df18870
diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.pyindex 199e1eab7d..5e6995ed4e 100644--- a/saleor/graphql/core/mutations.py+++ b/saleor/graphql/core/mutations.py@@ -4,6 +4,7 @@ import graphenefrom django.core.exceptions import ImproperlyConfigured, ValidationErrorfrom graphene.types.mutation import MutationOptionsfrom graphene_django.registry import get_global_registry+from graphql.error import GraphQLErrorfrom graphql_jwt import ObtainJSONWebToken, Verifyfrom graphql_jwt.exceptions import GraphQLJWTError, PermissionDenied@@ -131,7 +132,7 @@ class ModelMutation(BaseMutation):# handle ID fieldelif value is not None and field.type == graphene.ID:instance = cls.get_node_or_error(- info, value, errors, field=field.name)+ info, value, errors=errors, field=field.name)cleaned_input[field_name] = instance# handle uploaded files@@ -213,23 +214,21 @@ class ModelMutation(BaseMutation):instance.save()@classmethod- def get_node_or_error(cls, info, id, errors, only_type=None, field='Error'):+ def get_node_or_error(cls, info, id, errors, field, only_type=None):instance = Nonetry:instance = get_node(info, id, only_type)- except Exception as e:- cls.add_error(- field=field, message=str(e), errors=errors)+ except GraphQLError as e:+ cls.add_error(field=field, message=str(e), errors=errors)return instance@classmethod- def get_nodes_or_error(cls, ids, errors, graphene_type=None, field='Error'):+ def get_nodes_or_error(cls, ids, errors, field, graphene_type=None):instances = Nonetry:instances = get_nodes(ids, graphene_type)- except Exception as e:- cls.add_error(- field=field, message=str(e), errors=errors)+ except GraphQLError as e:+ cls.add_error(field=field, message=str(e), errors=errors)return instances@classmethoddiff --git a/saleor/graphql/utils.py b/saleor/graphql/utils.pyindex 03d29cd91c..3ddc0994ad 100644--- a/saleor/graphql/utils.py+++ b/saleor/graphql/utils.py@@ -3,6 +3,7 @@ from django.db.models import Qfrom django.utils.encoding import smart_textfrom django.utils.text import slugifyfrom graphene_django.registry import get_global_registry+from graphql.error import GraphQLErrorfrom graphql_relay import from_global_idfrom ..product.models import AttributeChoiceValue, ProductAttribute@@ -15,7 +16,7 @@ def get_node(info, id, only_type=None):"""Return node or throw an error if the node does not exist."""node = graphene.Node.get_node_from_global_id(info, id, only_type=only_type)if not node:- raise Exception(+ raise GraphQLError("Could not resolve to a node with the global id of '%s'." % id)return node@@ -52,7 +53,7 @@ def get_nodes(ids, graphene_type=None):nodes = list(graphene_type._meta.model.objects.filter(pk__in=pks))if not nodes:- raise Exception(+ raise GraphQLError("Could not resolve to a nodes with the global id list of '%s'."% ids)nodes_pk_list = [str(node.pk) for node in nodes]