Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move error code enums to separate files
Marcin Gębalaebe93d912331
diff --git a/saleor/account/error_codes.py b/saleor/account/error_codes.pynew file mode 100644index 0000000000..29d212b1e0--- /dev/null+++ b/saleor/account/error_codes.py@@ -0,0 +1,22 @@+from enum import Enum+++class AccountErrorCode(Enum):+ ACTIVATE_OWN_ACCOUNT = "activate_own_account"+ ACTIVATE_SUPERUSER_ACCOUNT = "activate_superuser_account"+ DEACTIVATE_OWN_ACCOUNT = "deactivate_own_account"+ DEACTIVATE_SUPERUSER_ACCOUNT = "deactivate_superuser_account"+ DELETE_NON_STAFF_USER = "delete_non_staff_user"+ DELETE_OWN_ACCOUNT = "delete_own_account"+ DELETE_STAFF_ACCOUNT = "delete_staff_account"+ DELETE_SUPERUSER_ACCOUNT = "delete_superuser_account"+ GRAPHQL_ERROR = "graphql_error"+ INVALID = "invalid"+ INVALID_PASSWORD = "invalid_password"+ NOT_FOUND = "not_found"+ PASSWORD_ENTIRELY_NUMERIC = "password_entirely_numeric"+ PASSWORD_TOO_COMMON = "password_too_common"+ PASSWORD_TOO_SHORT = "password_too_short"+ PASSWORD_TOO_SIMILAR = "password_too_similar"+ REQUIRED = "required"+ UNIQUE = "unique"diff --git a/saleor/account/validators.py b/saleor/account/validators.pyindex c5998b7a5c..f0042c28cd 100644--- a/saleor/account/validators.py+++ b/saleor/account/validators.py@@ -3,7 +3,7 @@ from django.utils.translation import ugettext_lazy as _from phonenumber_field.phonenumber import to_pythonfrom phonenumbers.phonenumberutil import is_possible_number-from ..graphql.core.utils.error_codes import AccountErrorCode+from .error_codes import AccountErrorCodedef validate_possible_number(phone, country=None):diff --git a/saleor/checkout/error_codes.py b/saleor/checkout/error_codes.pynew file mode 100644index 0000000000..3fbdefef44--- /dev/null+++ b/saleor/checkout/error_codes.py@@ -0,0 +1,22 @@+from enum import Enum+++class CheckoutErrorCode(Enum):+ BILLING_ADDRESS_NOT_SET = "billing_address_not_set"+ CHECKOUT_NOT_FULLY_PAID = "checkout_not_fully_paid"+ GRAPHQL_ERROR = "graphql_error"+ INSUFFICIENT_STOCK = "insufficient_stock"+ INVALID = "invalid"+ INVALID_SHIPPING_METHOD = "invalid_shipping_method"+ NOT_FOUND = "not_found"+ PAYMENT_ERROR = "payment_error"+ QUANTITY_GREATER_THAN_LIMIT = "quantity_greater_than_limit"+ REQUIRED = "required"+ SHIPPING_ADDRESS_NOT_SET = "shipping_address_not_set"+ SHIPPING_METHOD_NOT_APPLICABLE = "shipping_method_not_applicable"+ SHIPPING_METHOD_NOT_SET = "shipping_method_not_set"+ SHIPPING_NOT_REQUIRED = "shipping_not_required"+ TAX_ERROR = "tax_error"+ UNIQUE = "unique"+ VOUCHER_NOT_APPLICABLE = "voucher_not_applicable"+ ZERO_QUANTITY = "zero_quantity"diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex b827fa7dbc..ead6327988 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -16,6 +16,7 @@ from prices import Money, MoneyRange, TaxedMoneyRangefrom ..account.forms import get_address_formfrom ..account.models import Address, Userfrom ..account.utils import store_user_address+from ..checkout.error_codes import CheckoutErrorCodefrom ..core.exceptions import InsufficientStockfrom ..core.taxes import quantize_price, zero_taxed_moneyfrom ..core.utils import to_local_currency@@ -39,7 +40,6 @@ from ..giftcard.utils import (add_gift_card_code_to_checkout,remove_gift_card_code_from_checkout,)-from ..graphql.core.utils.error_codes import CheckoutErrorCodefrom ..order import eventsfrom ..order.emails import send_order_confirmationfrom ..order.models import Order, OrderLinediff --git a/saleor/core/error_codes.py b/saleor/core/error_codes.pynew file mode 100644index 0000000000..acc41963ce--- /dev/null+++ b/saleor/core/error_codes.py@@ -0,0 +1,11 @@+from enum import Enum+++class ShopErrorCode(Enum):+ ALREADY_EXISTS = "already_exists"+ CANNOT_FETCH_TAX_RATES = "cannot_fetch_tax_rates"+ GRAPHQL_ERROR = "graphql_error"+ INVALID = "invalid"+ NOT_FOUND = "not_found"+ REQUIRED = "required"+ UNIQUE = "unique"diff --git a/saleor/core/exceptions.py b/saleor/core/exceptions.pyindex 4df630603e..8497316fdf 100644--- a/saleor/core/exceptions.py+++ b/saleor/core/exceptions.py@@ -1,4 +1,4 @@-from ..graphql.core.utils.error_codes import CheckoutErrorCode+from ..checkout.error_codes import CheckoutErrorCodeclass InsufficientStock(Exception):diff --git a/saleor/core/utils/url.py b/saleor/core/utils/url.pyindex 2d1e64b3ec..a4ef24d873 100644--- a/saleor/core/utils/url.py+++ b/saleor/core/utils/url.py@@ -4,7 +4,7 @@ from django.conf import settingsfrom django.core.exceptions import ValidationErrorfrom django.http.request import split_domain_port, validate_host-from ...graphql.core.utils.error_codes import AccountErrorCode+from ...account.error_codes import AccountErrorCodedef validate_storefront_url(url):diff --git a/saleor/extensions/error_codes.py b/saleor/extensions/error_codes.pynew file mode 100644index 0000000000..67820b1829--- /dev/null+++ b/saleor/extensions/error_codes.py@@ -0,0 +1,10 @@+from enum import Enum+++class ExtensionsErrorCode(Enum):+ GRAPHQL_ERROR = "graphql_error"+ INVALID = "invalid"+ PLUGIN_MISCONFIGURED = "plugin-misconfigured"+ NOT_FOUND = "not_found"+ REQUIRED = "required"+ UNIQUE = "unique"diff --git a/saleor/extensions/plugins/avatax/plugin.py b/saleor/extensions/plugins/avatax/plugin.pyindex 34090ffabb..ae739fc219 100644--- a/saleor/extensions/plugins/avatax/plugin.py+++ b/saleor/extensions/plugins/avatax/plugin.py@@ -9,9 +9,9 @@ from django.utils.translation import pgettext_lazyfrom prices import Money, TaxedMoney, TaxedMoneyRangefrom ....core.taxes import TaxError, TaxType, zero_taxed_money-from ....graphql.core.utils.error_codes import ExtensionsErrorCodefrom ... import ConfigurationTypeFieldfrom ...base_plugin import BasePlugin+from ...error_codes import ExtensionsErrorCodefrom . import (META_FIELD,META_NAMESPACE,diff --git a/saleor/giftcard/error_codes.py b/saleor/giftcard/error_codes.pynew file mode 100644index 0000000000..ff1316b6f9--- /dev/null+++ b/saleor/giftcard/error_codes.py@@ -0,0 +1,10 @@+from enum import Enum+++class GiftcardErrorCode(Enum):+ ALREADY_EXISTS = "already_exists"+ GRAPHQL_ERROR = "graphql_error"+ INVALID = "invalid"+ NOT_FOUND = "not_found"+ REQUIRED = "required"+ UNIQUE = "unique"diff --git a/saleor/graphql/account/bulk_mutations.py b/saleor/graphql/account/bulk_mutations.pyindex 8ce8f2e7f3..7273981094 100644--- a/saleor/graphql/account/bulk_mutations.py+++ b/saleor/graphql/account/bulk_mutations.py@@ -2,8 +2,8 @@ import graphenefrom django.core.exceptions import ValidationErrorfrom ...account import models+from ...account.error_codes import AccountErrorCodefrom ..core.mutations import BaseBulkMutation, ModelBulkDeleteMutation-from ..core.utils.error_codes import AccountErrorCodefrom .mutations.base import AccountErrorMixinfrom .utils import CustomerDeleteMixin, StaffDeleteMixindiff --git a/saleor/graphql/account/i18n.py b/saleor/graphql/account/i18n.pyindex 48b6c27425..4bc45feb22 100644--- a/saleor/graphql/account/i18n.py+++ b/saleor/graphql/account/i18n.py@@ -1,10 +1,10 @@from django.core.exceptions import ValidationErrorfrom django_countries import countries+from ...account.error_codes import AccountErrorCodefrom ...account.forms import get_address_formfrom ...account.models import Addressfrom ...account.validators import validate_possible_number-from ..core.utils.error_codes import AccountErrorCodeclass I18nMixin:diff --git a/saleor/graphql/account/mutations/account.py b/saleor/graphql/account/mutations/account.pyindex bca514ea4d..362baa83ef 100644--- a/saleor/graphql/account/mutations/account.py+++ b/saleor/graphql/account/mutations/account.py@@ -3,12 +3,12 @@ from django.contrib.auth.tokens import default_token_generatorfrom django.core.exceptions import ValidationErrorfrom ....account import emails, events as account_events, models, utils+from ....account.error_codes import AccountErrorCodefrom ....checkout import AddressTypefrom ....core.utils.url import validate_storefront_urlfrom ...account.enums import AddressTypeEnumfrom ...account.types import Address, AddressInput, Userfrom ...core.mutations import ModelDeleteMutation, ModelMutation-from ...core.utils.error_codes import AccountErrorCodefrom .base import (INVALID_TOKEN,AccountErrorMixin,diff --git a/saleor/graphql/account/mutations/base.py b/saleor/graphql/account/mutations/base.pyindex ab3abb62ef..0a758b8164 100644--- a/saleor/graphql/account/mutations/base.py+++ b/saleor/graphql/account/mutations/base.py@@ -7,6 +7,7 @@ from graphql_jwt.exceptions import PermissionDeniedfrom ....account import events as account_events, modelsfrom ....account.emails import send_user_password_reset_email_with_url+from ....account.error_codes import AccountErrorCodefrom ....core.utils.url import validate_storefront_urlfrom ....dashboard.emails import send_set_password_email_with_urlfrom ...account.i18n import I18nMixin@@ -21,7 +22,6 @@ from ...core.mutations import (validation_error_to_error_type,)from ...core.types.common import AccountError-from ...core.utils.error_codes import AccountErrorCodeBILLING_ADDRESS_FIELD = "default_billing_address"SHIPPING_ADDRESS_FIELD = "default_shipping_address"diff --git a/saleor/graphql/account/mutations/deprecated_account.py b/saleor/graphql/account/mutations/deprecated_account.pyindex a2795c8bba..bd0fbba5d4 100644--- a/saleor/graphql/account/mutations/deprecated_account.py+++ b/saleor/graphql/account/mutations/deprecated_account.py@@ -2,11 +2,11 @@ import graphenefrom django.core.exceptions import ObjectDoesNotExist, ValidationErrorfrom ....account import events as account_events, models, utils+from ....account.error_codes import AccountErrorCodefrom ....checkout import AddressTypefrom ...account.enums import AddressTypeEnumfrom ...account.types import Address, AddressInput, Userfrom ...core.mutations import BaseMutation, ModelMutation-from ...core.utils.error_codes import AccountErrorCodefrom .base import BaseCustomerCreate, UserAddressInputfrom .deprecated_staff import send_user_password_reset_emaildiff --git a/saleor/graphql/account/mutations/deprecated_staff.py b/saleor/graphql/account/mutations/deprecated_staff.pyindex 713348a6b3..8c916877a9 100644--- a/saleor/graphql/account/mutations/deprecated_staff.py+++ b/saleor/graphql/account/mutations/deprecated_staff.py@@ -6,8 +6,8 @@ from django.utils.encoding import force_bytesfrom django.utils.http import urlsafe_base64_encodefrom ....account import emails, models+from ....account.error_codes import AccountErrorCodefrom ...core.mutations import BaseMutation-from ...core.utils.error_codes import AccountErrorCodedef send_user_password_reset_email(user, site):diff --git a/saleor/graphql/account/mutations/staff.py b/saleor/graphql/account/mutations/staff.pyindex 6946443101..2a4f32a44a 100644--- a/saleor/graphql/account/mutations/staff.py+++ b/saleor/graphql/account/mutations/staff.py@@ -6,6 +6,7 @@ from graphql_jwt.decorators import staff_member_requiredfrom graphql_jwt.exceptions import PermissionDeniedfrom ....account import events as account_events, models, utils+from ....account.error_codes import AccountErrorCodefrom ....account.thumbnails import create_user_avatar_thumbnailsfrom ....account.utils import get_random_avatarfrom ....checkout import AddressType@@ -24,7 +25,6 @@ from ...core.mutations import ()from ...core.types import Uploadfrom ...core.utils import validate_image_file-from ...core.utils.error_codes import AccountErrorCodefrom ..utils import CustomerDeleteMixin, StaffDeleteMixin, UserDeleteMixinfrom .base import (AccountErrorMixin,diff --git a/saleor/graphql/account/utils.py b/saleor/graphql/account/utils.pyindex 3e44d10cd4..a9a9a7e1a0 100644--- a/saleor/graphql/account/utils.py+++ b/saleor/graphql/account/utils.py@@ -2,7 +2,7 @@ from django.core.exceptions import ValidationErrorfrom graphene.utils.str_converters import to_camel_casefrom ...account import events as account_events-from ..core.utils.error_codes import AccountErrorCode+from ...account.error_codes import AccountErrorCodeclass UserDeleteMixin:diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex e1e7e17a21..5f50920143 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -7,6 +7,7 @@ from django.db import transactionfrom django.utils import timezonefrom ...checkout import models+from ...checkout.error_codes import CheckoutErrorCodefrom ...checkout.utils import (abort_order_data,add_promo_code_to_checkout,@@ -42,7 +43,6 @@ from ..core.mutations import ()from ..core.types.common import CheckoutErrorfrom ..core.utils import from_global_id_strict_type-from ..core.utils.error_codes import CheckoutErrorCodefrom ..order.types import Orderfrom ..product.types import ProductVariantfrom ..shipping.types import ShippingMethoddiff --git a/saleor/graphql/core/enums.py b/saleor/graphql/core/enums.pyindex b09a072b09..e7154ba486 100644--- a/saleor/graphql/core/enums.py+++ b/saleor/graphql/core/enums.py@@ -1,9 +1,19 @@import graphene+from ...account import error_codes as account_error_codes+from ...checkout import error_codes as checkout_error_codes+from ...core import error_codes as shop_error_codesfrom ...core.permissions import MODELS_PERMISSIONSfrom ...core.weight import WeightUnits+from ...extensions import error_codes as extensions_error_codesfrom ...extensions.plugins.vatlayer import TaxRateType as CoreTaxRateType-from .utils import error_codes, str_to_enum+from ...giftcard import error_codes as giftcard_error_codes+from ...menu import error_codes as menu_error_codes+from ...order import error_codes as order_error_codes+from ...payment import error_codes as payment_error_codes+from ...product import error_codes as product_error_codes+from ...shipping import error_codes as shipping_error_codes+from .utils import str_to_enum# FIXME CoreTaxRateType should be removed after we will drop old api fields dedicated# to taxes@@ -60,13 +70,15 @@ WeightUnitsEnum = graphene.Enum()-AccountErrorCode = graphene.Enum.from_enum(error_codes.AccountErrorCode)-CheckoutErrorCode = graphene.Enum.from_enum(error_codes.CheckoutErrorCode)-MenuErrorCode = graphene.Enum.from_enum(error_codes.MenuErrorCode)-OrderErrorCode = graphene.Enum.from_enum(error_codes.OrderErrorCode)-ProductErrorCode = graphene.Enum.from_enum(error_codes.ProductErrorCode)-ShopErrorCode = graphene.Enum.from_enum(error_codes.ShopErrorCode)-ShippingErrorCode = graphene.Enum.from_enum(error_codes.ShippingErrorCode)-PaymentErrorCode = graphene.Enum.from_enum(error_codes.PaymentErrorCode)-GiftcardErrorCode = graphene.Enum.from_enum(error_codes.GiftcardErrorCode)-ExtensionsErrorCode = graphene.Enum.from_enum(error_codes.ExtensionsErrorCode)+AccountErrorCode = graphene.Enum.from_enum(account_error_codes.AccountErrorCode)+CheckoutErrorCode = graphene.Enum.from_enum(checkout_error_codes.CheckoutErrorCode)+ExtensionsErrorCode = graphene.Enum.from_enum(+ extensions_error_codes.ExtensionsErrorCode+)+GiftcardErrorCode = graphene.Enum.from_enum(giftcard_error_codes.GiftcardErrorCode)+MenuErrorCode = graphene.Enum.from_enum(menu_error_codes.MenuErrorCode)+OrderErrorCode = graphene.Enum.from_enum(order_error_codes.OrderErrorCode)+PaymentErrorCode = graphene.Enum.from_enum(payment_error_codes.PaymentErrorCode)+ProductErrorCode = graphene.Enum.from_enum(product_error_codes.ProductErrorCode)+ShopErrorCode = graphene.Enum.from_enum(shop_error_codes.ShopErrorCode)+ShippingErrorCode = graphene.Enum.from_enum(shipping_error_codes.ShippingErrorCode)diff --git a/saleor/graphql/core/utils/error_codes.py b/saleor/graphql/core/utils/error_codes.pyindex bedb3a823a..a24adf7afa 100644--- a/saleor/graphql/core/utils/error_codes.py+++ b/saleor/graphql/core/utils/error_codes.py@@ -1,5 +1,16 @@from enum import Enum+from ....account.error_codes import AccountErrorCode+from ....checkout.error_codes import CheckoutErrorCode+from ....core.error_codes import ShopErrorCode+from ....extensions.error_codes import ExtensionsErrorCode+from ....giftcard.error_codes import GiftcardErrorCode+from ....menu.error_codes import MenuErrorCode+from ....order.error_codes import OrderErrorCode+from ....payment.error_codes import PaymentErrorCode+from ....product.error_codes import ProductErrorCode+from ....shipping.error_codes import ShippingErrorCode+DJANGO_VALIDATORS_ERROR_CODES = ["invalid","invalid_extension",@@ -28,146 +39,6 @@ DJANGO_FORM_FIELDS_ERROR_CODES = []-class AccountErrorCode(Enum):- ACTIVATE_OWN_ACCOUNT = "activate_own_account"- ACTIVATE_SUPERUSER_ACCOUNT = "activate_superuser_account"- DEACTIVATE_OWN_ACCOUNT = "deactivate_own_account"- DEACTIVATE_SUPERUSER_ACCOUNT = "deactivate_superuser_account"- DELETE_NON_STAFF_USER = "delete_non_staff_user"- DELETE_OWN_ACCOUNT = "delete_own_account"- DELETE_STAFF_ACCOUNT = "delete_staff_account"- DELETE_SUPERUSER_ACCOUNT = "delete_superuser_account"- GRAPHQL_ERROR = "graphql_error"- INVALID = "invalid"- INVALID_PASSWORD = "invalid_password"- NOT_FOUND = "not_found"- PASSWORD_ENTIRELY_NUMERIC = "password_entirely_numeric"- PASSWORD_TOO_COMMON = "password_too_common"- PASSWORD_TOO_SHORT = "password_too_short"- PASSWORD_TOO_SIMILAR = "password_too_similar"- REQUIRED = "required"- UNIQUE = "unique"---class CheckoutErrorCode(Enum):- BILLING_ADDRESS_NOT_SET = "billing_address_not_set"- CHECKOUT_NOT_FULLY_PAID = "checkout_not_fully_paid"- GRAPHQL_ERROR = "graphql_error"- INSUFFICIENT_STOCK = "insufficient_stock"- INVALID = "invalid"- INVALID_SHIPPING_METHOD = "invalid_shipping_method"- NOT_FOUND = "not_found"- PAYMENT_ERROR = "payment_error"- QUANTITY_GREATER_THAN_LIMIT = "quantity_greater_than_limit"- REQUIRED = "required"- SHIPPING_ADDRESS_NOT_SET = "shipping_address_not_set"- SHIPPING_METHOD_NOT_APPLICABLE = "shipping_method_not_applicable"- SHIPPING_METHOD_NOT_SET = "shipping_method_not_set"- SHIPPING_NOT_REQUIRED = "shipping_not_required"- TAX_ERROR = "tax_error"- UNIQUE = "unique"- VOUCHER_NOT_APPLICABLE = "voucher_not_applicable"- ZERO_QUANTITY = "zero_quantity"---class MenuErrorCode(Enum):- CANNOT_ASSIGN_NODE = "cannot_assign_node"- GRAPHQL_ERROR = "graphql_error"- INVALID = "invalid"- INVALID_MENU_ITEM = "invalid_menu_item"- NO_MENU_ITEM_PROVIDED = "no_item_provided"- NOT_FOUND = "not_found"- REQUIRED = "required"- TOO_MANY_MENU_ITEMS = "too_many_items"- UNIQUE = "unique"---class OrderErrorCode(Enum):- CANNOT_CANCEL_FULFILLMENT = "cannot_cancel_fulfillment"- CANNOT_CANCEL_ORDER = "cannot_cancel_order"- CANNOT_DELETE = "cannot_delete"- CANNOT_REFUND = "cannot_refund"- CAPTURE_INACTIVE_PAYMENT = "capture_inactive_payment"- EDIT_NON_DRAFT_ORDER = "edit_non_draft_order"- FULFILL_ORDER_LINE = "fulfill_order_line"- GRAPHQL_ERROR = "graphql_error"- INVALID = "invalid"- NOT_FOUND = "not_found"- ORDER_INVALID_SHIPPING_METHOD = "order_invalid_shipping_method"- ORDER_NO_SHIPPING_ADDRESS = "order_no_shipping_address"- PAYMENT_ERROR = "payment_error"- PAYMENT_MISSING = "payment_missing"- REQUIRED = "required"- SHIPPING_METHOD_REQUIRED = "shipping_method_required"- UNIQUE = "unique"- VOID_INACTIVE_PAYMENT = "void_inactive_payment"- ZERO_QUANTITY = "zero_quantity"---class ProductErrorCode(Enum):- ALREADY_EXISTS = "already_exists"- ATTRIBUTE_ALREADY_ASSIGNED = "attribute_already_assigned"- ATTRIBUTE_BAD_VALUE = "attribute_bad_value"- ATTRIBUTE_CANNOT_BE_ASSIGNED = "attribute_cannot_be_assigned"- ATTRIBUTE_DISABLED_VARIANTS = "attribute_disabled_variants"- GRAPHQL_ERROR = "graphql_error"- INVALID = "invalid"- NOT_PRODUCTS_IMAGE = "not_products_image"- NOT_FOUND = "not_found"- REQUIRED = "required"- UNIQUE = "unique"- VARIANT_NO_DIGITAL_CONTENT = "variant_no_digital_content"---class ShopErrorCode(Enum):- ALREADY_EXISTS = "already_exists"- CANNOT_FETCH_TAX_RATES = "cannot_fetch_tax_rates"- GRAPHQL_ERROR = "graphql_error"- INVALID = "invalid"- NOT_FOUND = "not_found"- REQUIRED = "required"- UNIQUE = "unique"---class ShippingErrorCode(Enum):- ALREADY_EXISTS = "already_exists"- GRAPHQL_ERROR = "graphql_error"- INVALID = "invalid"- MAX_LESS_THAN_MIN = "max_less_than_min"- NOT_FOUND = "not_found"- REQUIRED = "required"- UNIQUE = "unique"---class PaymentErrorCode(Enum):- BILLING_ADDRESS_NOT_SET = "billing_address_not_set"- GRAPHQL_ERROR = "graphql_error"- INVALID = "invalid"- NOT_FOUND = "not_found"- PARTIAL_PAYMENT_NOT_ALLOWED = "partial_payment_not_allowed"- PAYMENT_ERROR = "payment_error"- REQUIRED = "required"- UNIQUE = "unique"---class GiftcardErrorCode(Enum):- ALREADY_EXISTS = "already_exists"- GRAPHQL_ERROR = "graphql_error"- INVALID = "invalid"- NOT_FOUND = "not_found"- REQUIRED = "required"- UNIQUE = "unique"---class ExtensionsErrorCode(Enum):- GRAPHQL_ERROR = "graphql_error"- INVALID = "invalid"- PLUGIN_MISCONFIGURED = "plugin-misconfigured"- NOT_FOUND = "not_found"- REQUIRED = "required"- UNIQUE = "unique"--SALEOR_ERROR_CODE_ENUMS = [AccountErrorCode,CheckoutErrorCode,diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.pyindex 7913fa7889..34b5594eb3 100644--- a/saleor/graphql/giftcard/mutations.py+++ b/saleor/graphql/giftcard/mutations.py@@ -8,11 +8,11 @@ from ...core.utils.promo_code import (is_available_promo_code,)from ...giftcard import models+from ...giftcard.error_codes import GiftcardErrorCodefrom ...giftcard.utils import activate_gift_card, deactivate_gift_cardfrom ..core.mutations import BaseMutation, ModelMutationfrom ..core.scalars import Decimalfrom ..core.types.common import GiftcardError-from ..core.utils.error_codes import GiftcardErrorCodefrom .types import GiftCarddiff --git a/saleor/graphql/menu/mutations.py b/saleor/graphql/menu/mutations.pyindex 13421f99d5..96949d81e8 100644--- a/saleor/graphql/menu/mutations.py+++ b/saleor/graphql/menu/mutations.py@@ -7,12 +7,12 @@ from django.db.models import Modelfrom graphql_relay import from_global_idfrom ...menu import models+from ...menu.error_codes import MenuErrorCodefrom ...menu.utils import update_menufrom ...page import models as page_modelsfrom ...product import models as product_modelsfrom ..core.mutations import BaseMutation, ModelDeleteMutation, ModelMutationfrom ..core.types.common import MenuError-from ..core.utils.error_codes import MenuErrorCodefrom ..page.types import Pagefrom ..product.types import Category, Collectionfrom .enums import NavigationTypediff --git a/saleor/graphql/order/bulk_mutations/draft_orders.py b/saleor/graphql/order/bulk_mutations/draft_orders.pyindex 12f2b1ca33..48f8914ab1 100644--- a/saleor/graphql/order/bulk_mutations/draft_orders.py+++ b/saleor/graphql/order/bulk_mutations/draft_orders.py@@ -2,8 +2,8 @@ import graphenefrom django.core.exceptions import ValidationErrorfrom ....order import OrderStatus, models+from ....order.error_codes import OrderErrorCodefrom ...core.mutations import ModelBulkDeleteMutation-from ...core.utils.error_codes import OrderErrorCodefrom ..mutations.base import OrderErrorMixindiff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.pyindex 935e680f0f..c304b1383d 100644--- a/saleor/graphql/order/mutations/draft_orders.py+++ b/saleor/graphql/order/mutations/draft_orders.py@@ -6,6 +6,7 @@ from ....account.models import Userfrom ....core.exceptions import InsufficientStockfrom ....core.taxes import zero_taxed_moneyfrom ....order import OrderStatus, events, models+from ....order.error_codes import OrderErrorCodefrom ....order.utils import (add_variant_to_order,allocate_stock,@@ -18,7 +19,6 @@ from ...account.i18n import I18nMixinfrom ...account.types import AddressInputfrom ...core.mutations import ModelDeleteMutation, ModelMutationfrom ...core.scalars import Decimal-from ...core.utils.error_codes import OrderErrorCodefrom ...product.types import ProductVariantfrom ..types import Order, OrderLinefrom ..utils import validate_draft_orderdiff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.pyindex a9c15f158e..16a592d78e 100644--- a/saleor/graphql/order/mutations/fulfillments.py+++ b/saleor/graphql/order/mutations/fulfillments.py@@ -4,8 +4,8 @@ from django.utils.translation import npgettext_lazy, pgettext_lazyfrom ....order import events, modelsfrom ....order.emails import send_fulfillment_confirmation_to_customer+from ....order.error_codes import OrderErrorCodefrom ....order.utils import cancel_fulfillment, fulfill_order_line, update_order_status-from ...core.utils.error_codes import OrderErrorCodefrom ...order.types import Fulfillment, Orderfrom ..types import OrderLinefrom .base import BaseOrderMutationdiff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.pyindex 0d84dc844e..edd9baba6c 100644--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@ -4,6 +4,7 @@ from django.core.exceptions import ValidationErrorfrom ....account.models import Userfrom ....core.taxes import zero_taxed_moneyfrom ....order import events, models+from ....order.error_codes import OrderErrorCodefrom ....order.utils import (cancel_order,get_valid_shipping_methods_for_order,@@ -19,7 +20,6 @@ from ....payment.utils import ()from ...account.types import AddressInputfrom ...core.scalars import Decimal-from ...core.utils.error_codes import OrderErrorCodefrom ...order.mutations.draft_orders import DraftOrderUpdatefrom ...order.types import Order, OrderEventfrom ...shipping.types import ShippingMethoddiff --git a/saleor/graphql/order/utils.py b/saleor/graphql/order/utils.pyindex dd008b220b..c03dab0772 100644--- a/saleor/graphql/order/utils.py+++ b/saleor/graphql/order/utils.py@@ -1,6 +1,6 @@from django.core.exceptions import ValidationError-from ..core.utils.error_codes import OrderErrorCode+from ...order.error_codes import OrderErrorCodedef validate_total_quantity(order):diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 0a785726a1..9ededb9be6 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -5,6 +5,7 @@ from django.core.exceptions import ValidationErrorfrom ...core.taxes import zero_taxed_moneyfrom ...core.utils import get_client_ipfrom ...payment import PaymentError, models+from ...payment.error_codes import PaymentErrorCodefrom ...payment.utils import (create_payment,gateway_capture,@@ -19,7 +20,6 @@ from ..core.mutations import BaseMutationfrom ..core.scalars import Decimalfrom ..core.types import common as common_typesfrom ..core.utils import from_global_id_strict_type-from ..core.utils.error_codes import PaymentErrorCodefrom .enums import PaymentGatewayEnumfrom .types import Paymentdiff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.pyindex ca990f6450..864e2650ef 100644--- a/saleor/graphql/product/mutations/attributes.py+++ b/saleor/graphql/product/mutations/attributes.py@@ -7,6 +7,7 @@ from django.db.models import Qfrom django.template.defaultfilters import slugifyfrom ....product import AttributeInputType, models+from ....product.error_codes import ProductErrorCodefrom ...core.mutations import (ClearMetaBaseMutation,ModelDeleteMutation,@@ -14,7 +15,6 @@ from ...core.mutations import (UpdateMetaBaseMutation,)from ...core.utils import from_global_id_strict_type-from ...core.utils.error_codes import ProductErrorCodefrom ...core.utils.reordering import perform_reorderingfrom ...product.types import ProductTypefrom ..descriptions import AttributeDescriptions, AttributeValueDescriptionsdiff --git a/saleor/graphql/product/mutations/digital_contents.py b/saleor/graphql/product/mutations/digital_contents.pyindex 81a429d659..656755e10d 100644--- a/saleor/graphql/product/mutations/digital_contents.py+++ b/saleor/graphql/product/mutations/digital_contents.py@@ -2,9 +2,9 @@ import graphenefrom django.core.exceptions import ValidationErrorfrom ....product import models+from ....product.error_codes import ProductErrorCodefrom ...core.mutations import ModelMutationfrom ...core.types import Upload-from ...core.utils.error_codes import ProductErrorCodefrom ...decorators import permission_requiredfrom ..types import DigitalContent, ProductVariantfrom .base import BaseProductMutation, ProductErrorMixindiff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 587a6bcbc7..88aa82de88 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -9,6 +9,7 @@ from graphene.types import InputObjectTypefrom graphql_relay import from_global_idfrom ....product import models+from ....product.error_codes import ProductErrorCodefrom ....product.tasks import (update_product_minimal_variant_price_task,update_products_minimal_variant_prices_of_catalogues_task,@@ -35,7 +36,6 @@ from ...core.utils import (from_global_id_strict_type,validate_image_file,)-from ...core.utils.error_codes import ProductErrorCodefrom ...core.utils.reordering import perform_reorderingfrom ..types import (Category,diff --git a/saleor/graphql/shipping/mutations.py b/saleor/graphql/shipping/mutations.pyindex b8436f6392..734a3bdba5 100644--- a/saleor/graphql/shipping/mutations.py+++ b/saleor/graphql/shipping/mutations.py@@ -3,10 +3,10 @@ from django.core.exceptions import ValidationErrorfrom ...dashboard.shipping.forms import default_shipping_zone_existsfrom ...shipping import models+from ...shipping.error_codes import ShippingErrorCodefrom ..core.mutations import BaseMutation, ModelDeleteMutation, ModelMutationfrom ..core.scalars import Decimal, WeightScalarfrom ..core.types.common import ShippingError-from ..core.utils.error_codes import ShippingErrorCodefrom .enums import ShippingMethodTypeEnumfrom .types import ShippingMethod, ShippingZonediff --git a/saleor/graphql/shop/mutations.py b/saleor/graphql/shop/mutations.pyindex d5fcbe2648..15888c4c24 100644--- a/saleor/graphql/shop/mutations.py+++ b/saleor/graphql/shop/mutations.py@@ -4,13 +4,13 @@ from django.core.exceptions import ValidationErrorfrom django.core.management import call_commandfrom ...account.models import Address+from ...core.error_codes import ShopErrorCodefrom ...site import models as site_modelsfrom ..account.i18n import I18nMixinfrom ..account.types import AddressInputfrom ..core.enums import WeightUnitsEnumfrom ..core.mutations import BaseMutationfrom ..core.types.common import ShopError-from ..core.utils.error_codes import ShopErrorCodefrom ..product.types import Collectionfrom .types import AuthorizationKey, AuthorizationKeyType, Shopdiff --git a/saleor/menu/error_codes.py b/saleor/menu/error_codes.pynew file mode 100644index 0000000000..5973d477e4--- /dev/null+++ b/saleor/menu/error_codes.py@@ -0,0 +1,13 @@+from enum import Enum+++class MenuErrorCode(Enum):+ CANNOT_ASSIGN_NODE = "cannot_assign_node"+ GRAPHQL_ERROR = "graphql_error"+ INVALID = "invalid"+ INVALID_MENU_ITEM = "invalid_menu_item"+ NO_MENU_ITEM_PROVIDED = "no_item_provided"+ NOT_FOUND = "not_found"+ REQUIRED = "required"+ TOO_MANY_MENU_ITEMS = "too_many_items"+ UNIQUE = "unique"diff --git a/saleor/order/error_codes.py b/saleor/order/error_codes.pynew file mode 100644index 0000000000..e380da0bee--- /dev/null+++ b/saleor/order/error_codes.py@@ -0,0 +1,23 @@+from enum import Enum+++class OrderErrorCode(Enum):+ CANNOT_CANCEL_FULFILLMENT = "cannot_cancel_fulfillment"+ CANNOT_CANCEL_ORDER = "cannot_cancel_order"+ CANNOT_DELETE = "cannot_delete"+ CANNOT_REFUND = "cannot_refund"+ CAPTURE_INACTIVE_PAYMENT = "capture_inactive_payment"+ EDIT_NON_DRAFT_ORDER = "edit_non_draft_order"+ FULFILL_ORDER_LINE = "fulfill_order_line"+ GRAPHQL_ERROR = "graphql_error"+ INVALID = "invalid"+ NOT_FOUND = "not_found"+ ORDER_INVALID_SHIPPING_METHOD = "order_invalid_shipping_method"+ ORDER_NO_SHIPPING_ADDRESS = "order_no_shipping_address"+ PAYMENT_ERROR = "payment_error"+ PAYMENT_MISSING = "payment_missing"+ REQUIRED = "required"+ SHIPPING_METHOD_REQUIRED = "shipping_method_required"+ UNIQUE = "unique"+ VOID_INACTIVE_PAYMENT = "void_inactive_payment"+ ZERO_QUANTITY = "zero_quantity"diff --git a/saleor/payment/error_codes.py b/saleor/payment/error_codes.pynew file mode 100644index 0000000000..a03361b310--- /dev/null+++ b/saleor/payment/error_codes.py@@ -0,0 +1,12 @@+from enum import Enum+++class PaymentErrorCode(Enum):+ BILLING_ADDRESS_NOT_SET = "billing_address_not_set"+ GRAPHQL_ERROR = "graphql_error"+ INVALID = "invalid"+ NOT_FOUND = "not_found"+ PARTIAL_PAYMENT_NOT_ALLOWED = "partial_payment_not_allowed"+ PAYMENT_ERROR = "payment_error"+ REQUIRED = "required"+ UNIQUE = "unique"diff --git a/saleor/payment/gateways/braintree/forms.py b/saleor/payment/gateways/braintree/forms.pyindex 6e3e07674b..f920d386d4 100644--- a/saleor/payment/gateways/braintree/forms.py+++ b/saleor/payment/gateways/braintree/forms.py@@ -2,7 +2,7 @@ from django import formsfrom django.core.exceptions import ValidationErrorfrom django.utils.translation import pgettext_lazy-from ....graphql.core.utils.error_codes import PaymentErrorCode+from ...error_codes import PaymentErrorCodefrom ...interface import PaymentDatadiff --git a/saleor/product/error_codes.py b/saleor/product/error_codes.pynew file mode 100644index 0000000000..df2a238d15--- /dev/null+++ b/saleor/product/error_codes.py@@ -0,0 +1,16 @@+from enum import Enum+++class ProductErrorCode(Enum):+ ALREADY_EXISTS = "already_exists"+ ATTRIBUTE_ALREADY_ASSIGNED = "attribute_already_assigned"+ ATTRIBUTE_BAD_VALUE = "attribute_bad_value"+ ATTRIBUTE_CANNOT_BE_ASSIGNED = "attribute_cannot_be_assigned"+ ATTRIBUTE_DISABLED_VARIANTS = "attribute_disabled_variants"+ GRAPHQL_ERROR = "graphql_error"+ INVALID = "invalid"+ NOT_PRODUCTS_IMAGE = "not_products_image"+ NOT_FOUND = "not_found"+ REQUIRED = "required"+ UNIQUE = "unique"+ VARIANT_NO_DIGITAL_CONTENT = "variant_no_digital_content"diff --git a/saleor/shipping/error_codes.py b/saleor/shipping/error_codes.pynew file mode 100644index 0000000000..6e95ac74a5--- /dev/null+++ b/saleor/shipping/error_codes.py@@ -0,0 +1,11 @@+from enum import Enum+++class ShippingErrorCode(Enum):+ ALREADY_EXISTS = "already_exists"+ GRAPHQL_ERROR = "graphql_error"+ INVALID = "invalid"+ MAX_LESS_THAN_MIN = "max_less_than_min"+ NOT_FOUND = "not_found"+ REQUIRED = "required"+ UNIQUE = "unique"diff --git a/tests/api/test_account.py b/tests/api/test_account.pyindex b3b72fc8d5..69b97b539b 100644--- a/tests/api/test_account.py+++ b/tests/api/test_account.py@@ -14,6 +14,7 @@ from freezegun import freeze_timefrom prices import Moneyfrom saleor.account import events as account_events+from saleor.account.error_codes import AccountErrorCodefrom saleor.account.models import Address, Userfrom saleor.account.utils import get_random_avatarfrom saleor.checkout import AddressType@@ -26,7 +27,6 @@ from saleor.graphql.account.mutations.staff import ()from saleor.graphql.core.enums import PermissionEnumfrom saleor.graphql.core.utils import str_to_enum-from saleor.graphql.core.utils.error_codes import AccountErrorCodefrom saleor.order.models import FulfillmentStatus, Orderfrom tests.api.utils import get_graphql_contentfrom tests.utils import create_image@@ -1668,7 +1668,7 @@ def test_set_password_invalid_email(user_api_client):account_errors = content["data"]["setPassword"]["accountErrors"]assert len(account_errors) == 1assert account_errors[0]["field"] == "email"- assert account_errors[0]["code"] == "NOT_FOUND"+ assert account_errors[0]["code"] == AccountErrorCode.NOT_FOUND.namedef test_set_password_invalid_password(user_api_client, customer_user, settings):diff --git a/tests/api/test_attributes.py b/tests/api/test_attributes.pyindex 89764f58e5..6d819714af 100644--- a/tests/api/test_attributes.py+++ b/tests/api/test_attributes.py@@ -8,11 +8,11 @@ from django.template.defaultfilters import slugifyfrom graphene.utils.str_converters import to_camel_casefrom saleor.graphql.core.utils import snake_to_camel_case-from saleor.graphql.core.utils.error_codes import ProductErrorCodefrom saleor.graphql.product.enums import AttributeTypeEnum, AttributeValueTypefrom saleor.graphql.product.mutations.attributes import validate_value_is_uniquefrom saleor.graphql.product.types.attributes import resolve_attribute_value_typefrom saleor.product import AttributeInputType+from saleor.product.error_codes import ProductErrorCodefrom saleor.product.models import (Attribute,AttributeProduct,diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.pyindex 5ff340f66d..eb3af03ffa 100644--- a/tests/api/test_checkout.py+++ b/tests/api/test_checkout.py@@ -7,6 +7,7 @@ import pytestfrom django.core.exceptions import ValidationErrorfrom prices import Money, TaxedMoney+from saleor.checkout.error_codes import CheckoutErrorCodefrom saleor.checkout.models import Checkoutfrom saleor.checkout.utils import clean_checkout, is_fully_paidfrom saleor.core.taxes import zero_money@@ -15,7 +16,6 @@ from saleor.graphql.checkout.mutations import (update_checkout_shipping_method_if_invalid,)from saleor.graphql.core.utils import str_to_enum-from saleor.graphql.core.utils.error_codes import CheckoutErrorCodefrom saleor.order.models import Orderfrom saleor.payment import PaymentErrorfrom saleor.payment.models import Transaction@@ -252,7 +252,7 @@ def test_checkout_create_required_email(api_client, variant):assert errors[0]["message"] == "This field cannot be blank."checkout_errors = content["data"]["checkoutCreate"]["checkoutErrors"]- assert checkout_errors[0]["code"] == "REQUIRED"+ assert checkout_errors[0]["code"] == CheckoutErrorCode.REQUIRED.namedef test_checkout_create_default_email_for_logged_in_customer(user_api_client, variant):@@ -1029,7 +1029,7 @@ def test_checkout_email_update_validation(user_api_client, checkout_with_item):assert errors[0]["message"] == "This field cannot be blank."checkout_errors = content["data"]["checkoutEmailUpdate"]["checkoutErrors"]- assert checkout_errors[0]["code"] == "REQUIRED"+ assert checkout_errors[0]["code"] == CheckoutErrorCode.REQUIRED.nameMUTATION_CHECKOUT_COMPLETE = """diff --git a/tests/api/test_checkout_digital.py b/tests/api/test_checkout_digital.pyindex 737ee10890..ac61a698eb 100644--- a/tests/api/test_checkout_digital.py+++ b/tests/api/test_checkout_digital.py@@ -4,9 +4,9 @@ from graphene import Nodefrom prices import TaxedMoneyfrom saleor.account.models import Address+from saleor.checkout.error_codes import CheckoutErrorCodefrom saleor.checkout.models import Checkoutfrom saleor.checkout.utils import add_variant_to_checkout-from saleor.graphql.core.utils.error_codes import CheckoutErrorCodefrom saleor.order.models import Orderfrom tests.api.utils import get_graphql_contentdiff --git a/tests/api/test_digital_content.py b/tests/api/test_digital_content.pyindex 92aaae4062..0f67ade10d 100644--- a/tests/api/test_digital_content.py+++ b/tests/api/test_digital_content.py@@ -1,6 +1,6 @@import graphene-from saleor.graphql.core.utils.error_codes import ProductErrorCode+from saleor.product.error_codes import ProductErrorCodefrom saleor.product.models import DigitalContent, ProductVariantfrom tests.api.utils import get_graphql_contentfrom tests.utils import create_imagediff --git a/tests/api/test_gift_card.py b/tests/api/test_gift_card.pyindex 4d4ab6e54a..e11dd6cc16 100644--- a/tests/api/test_gift_card.py+++ b/tests/api/test_gift_card.py@@ -2,6 +2,7 @@ from datetime import dateimport graphene+from saleor.giftcard.error_codes import GiftcardErrorCodefrom tests.api.utils import get_graphql_contentfrom .utils import assert_no_permission@@ -289,7 +290,7 @@ def test_create_gift_card_with_existing_voucher_code(assert errors[0]["field"] == "promoCode"gift_card_errors = content["data"]["giftCardCreate"]["giftCardErrors"]- assert gift_card_errors[0]["code"] == "ALREADY_EXISTS"+ assert gift_card_errors[0]["code"] == GiftcardErrorCode.ALREADY_EXISTS.namedef test_create_gift_card_with_existing_gift_card_code(@@ -307,7 +308,7 @@ def test_create_gift_card_with_existing_gift_card_code(assert errors[0]["field"] == "promoCode"gift_card_errors = content["data"]["giftCardCreate"]["giftCardErrors"]- assert gift_card_errors[0]["code"] == "ALREADY_EXISTS"+ assert gift_card_errors[0]["code"] == GiftcardErrorCode.ALREADY_EXISTS.namedef test_create_gift_card_without_user(staff_api_client, permission_manage_gift_card):@@ -360,7 +361,7 @@ def test_create_gift_card_with_incorrect_user_email(assert errors[0]["message"] == "Customer with this email doesn't exist."gift_card_errors = content["data"]["giftCardCreate"]["giftCardErrors"]- assert gift_card_errors[0]["code"] == "NOT_FOUND"+ assert gift_card_errors[0]["code"] == GiftcardErrorCode.NOT_FOUND.namedef test_create_gift_card_without_premissions(staff_api_client):diff --git a/tests/api/test_order.py b/tests/api/test_order.pyindex 8a57804869..e12dca12d2 100644--- a/tests/api/test_order.py+++ b/tests/api/test_order.py@@ -11,7 +11,6 @@ from prices import Money, TaxedMoneyfrom saleor.account.models import CustomerEventfrom saleor.core.taxes import zero_taxed_moneyfrom saleor.graphql.core.enums import ReportingPeriod-from saleor.graphql.core.utils.error_codes import OrderErrorCodefrom saleor.graphql.order.mutations.orders import (clean_order_cancel,clean_order_capture,@@ -21,6 +20,7 @@ from saleor.graphql.order.mutations.orders import (from saleor.graphql.order.utils import validate_draft_orderfrom saleor.graphql.payment.types import PaymentChargeStatusEnumfrom saleor.order import OrderStatus, events as order_events+from saleor.order.error_codes import OrderErrorCodefrom saleor.order.models import Order, OrderEventfrom saleor.payment import ChargeStatus, CustomPaymentChoices, PaymentErrorfrom saleor.payment.models import Payment