Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Allow plugins to create their custom error code (#9300)
LeOndazefd87586f5dd
diff --git a/saleor/graphql/core/utils/error_codes.py b/saleor/graphql/core/utils/error_codes.pyindex 0fe50a2876..a980cce071 100644--- a/saleor/graphql/core/utils/error_codes.py+++ b/saleor/graphql/core/utils/error_codes.py@@ -1,30 +1,5 @@from enum import Enum-from ....account.error_codes import AccountErrorCode, PermissionGroupErrorCode-from ....app.error_codes import AppErrorCode-from ....attribute.error_codes import AttributeErrorCode-from ....channel.error_codes import ChannelErrorCode-from ....checkout.error_codes import CheckoutErrorCode-from ....core.error_codes import (- MetadataErrorCode,- ShopErrorCode,- TranslationErrorCode,- UploadErrorCode,-)-from ....csv.error_codes import ExportErrorCode-from ....discount.error_codes import DiscountErrorCode-from ....giftcard.error_codes import GiftCardErrorCode-from ....invoice.error_codes import InvoiceErrorCode-from ....menu.error_codes import MenuErrorCode-from ....order.error_codes import OrderErrorCode-from ....page.error_codes import PageErrorCode-from ....payment.error_codes import PaymentErrorCode-from ....plugins.error_codes import PluginErrorCode-from ....product.error_codes import ProductErrorCode-from ....shipping.error_codes import ShippingErrorCode-from ....site.error_codes import GiftCardSettingsErrorCode, OrderSettingsErrorCode-from ...notifications.error_codes import ExternalNotificationErrorCodes-DJANGO_VALIDATORS_ERROR_CODES = ["invalid","invalid_extension",@@ -53,38 +28,6 @@ DJANGO_FORM_FIELDS_ERROR_CODES = []-SALEOR_ERROR_CODE_ENUMS = [- AccountErrorCode,- AppErrorCode,- AttributeErrorCode,- ChannelErrorCode,- CheckoutErrorCode,- ExportErrorCode,- DiscountErrorCode,- GiftCardSettingsErrorCode,- ExternalNotificationErrorCodes,- PluginErrorCode,- GiftCardErrorCode,- InvoiceErrorCode,- MenuErrorCode,- MetadataErrorCode,- OrderErrorCode,- PageErrorCode,- PaymentErrorCode,- OrderSettingsErrorCode,- PermissionGroupErrorCode,- ProductErrorCode,- ShippingErrorCode,- ShopErrorCode,- TranslationErrorCode,- UploadErrorCode,-]--saleor_error_codes = []-for enum in SALEOR_ERROR_CODE_ENUMS:- saleor_error_codes.extend([code.value for code in enum])--def get_error_code_from_error(error) -> str:"""Return valid error code from ValidationError.@@ -96,10 +39,12 @@ def get_error_code_from_error(error) -> str:return "required"if code in ["unique", "unique_for_date"]:return "unique"- if code in DJANGO_VALIDATORS_ERROR_CODES or code in DJANGO_FORM_FIELDS_ERROR_CODES:+ if (+ code is None+ or code in DJANGO_VALIDATORS_ERROR_CODES+ or code in DJANGO_FORM_FIELDS_ERROR_CODES+ ):return "invalid"if isinstance(code, Enum):code = code.value- if code not in saleor_error_codes:- return "invalid"return codediff --git a/saleor/plugins/vatlayer/plugin.py b/saleor/plugins/vatlayer/plugin.pyindex dfbd4f9a18..c1a850fbab 100644--- a/saleor/plugins/vatlayer/plugin.py+++ b/saleor/plugins/vatlayer/plugin.py@@ -18,8 +18,8 @@ from prices import Money, TaxedMoney, TaxedMoneyRangefrom ...checkout import base_calculations, calculationsfrom ...checkout.interface import CheckoutTaxedPricesDatafrom ...core.taxes import TaxType-from ...graphql.core.utils.error_codes import PluginErrorCodefrom ...order.interface import OrderTaxedPricesData+from ...plugins.error_codes import PluginErrorCodefrom ...product.models import ProductTypefrom ..base_plugin import BasePlugin, ConfigurationTypeFieldfrom ..manager import get_plugins_manager