Skip to content

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

Add generic invalid token error code

Aleksander Spyra0674d22a0b3d
diff --git a/saleor/graphql/account/mutations/account.py b/saleor/graphql/account/mutations/account.py
index 111074358b..5c0eabf4f4 100644
--- a/saleor/graphql/account/mutations/account.py
+++ b/saleor/graphql/account/mutations/account.py
@@ -8,7 +8,7 @@ from ....core.utils.url import validate_storefront_url
from ...account.enums import AddressTypeEnum
from ...account.types import Address, AddressInput, User
from ...core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation
-from ...core.utils.error_codes import AccountErrorCode
+from ...core.utils.error_codes import AccountErrorCode, CommonErrorCode
from .base import (
INVALID_TOKEN,
BaseAddressDelete,
@@ -140,7 +140,7 @@ class AccountDelete(ModelDeleteMutation):
raise ValidationError(
{
"token": ValidationError(
- INVALID_TOKEN, code=AccountErrorCode.INVALID_USER_TOKEN
+ INVALID_TOKEN, code=CommonErrorCode.INVALID_TOKEN
)
}
)
diff --git a/saleor/graphql/account/mutations/base.py b/saleor/graphql/account/mutations/base.py
index 964e46ee59..9370ab32bf 100644
--- a/saleor/graphql/account/mutations/base.py
+++ b/saleor/graphql/account/mutations/base.py
@@ -83,7 +83,7 @@ class SetPassword(CreateToken):
raise ValidationError(
{
"token": ValidationError(
- INVALID_TOKEN, code=AccountErrorCode.INVALID_USER_TOKEN
+ INVALID_TOKEN, code=CommonErrorCode.INVALID_TOKEN
)
}
)
diff --git a/saleor/graphql/core/utils/error_codes.py b/saleor/graphql/core/utils/error_codes.py
index 21177a650e..f939b8c86a 100644
--- a/saleor/graphql/core/utils/error_codes.py
+++ b/saleor/graphql/core/utils/error_codes.py
@@ -50,7 +50,6 @@ class AccountErrorCode(Enum):
INVALID_COUNTRY = "invalid_country"
INVALID_PASSWORD = "invalid_password"
INVALID_PHONE_NUMBER = "invalid_phone_number"
- INVALID_USER_TOKEN = "invalid_user_token"
NOT_USERS_ADDRESS = "not_users_address"
@@ -99,6 +98,7 @@ class CommonErrorCode(Enum):
INCORRECT_VALUE = "incorrect_value"
INVALID_FILE_TYPE = "invalid_file_type"
INVALID_STOREFRONT_URL = "invalid_storefront_url"
+ INVALID_TOKEN = "invalid_token"
INVALID_WEIGHT_UNIT = "invalid_weight_unit"
MISSING_VALUE = "missing_value"
NON_BLANK_VALUE_REQUIRED = "non_blank_value_required"
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index ac9ffa5c9d..f69585a553 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -1434,7 +1434,7 @@ enum ErrorCode {
INVALID_SHIPPING_METHOD
INVALID_STOREFRONT_URL
INVALID_TIME
- INVALID_USER_TOKEN
+ INVALID_TOKEN
INVALID_WEIGHT_UNIT
LIMIT_VALUE
MAX_DECIMAL_PLACES
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index 0e15b6bc62..4b4414e6b4 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -26,7 +26,7 @@ from saleor.graphql.account.mutations.staff import (
)
from saleor.graphql.core.enums import PermissionEnum
from saleor.graphql.core.utils import str_to_enum
-from saleor.graphql.core.utils.error_codes import AccountErrorCode, CommonErrorCode
+from saleor.graphql.core.utils.error_codes import CommonErrorCode
from saleor.order.models import FulfillmentStatus, Order
from tests.api.utils import get_graphql_content
from tests.utils import create_image
@@ -1646,7 +1646,7 @@ def test_set_password_invalid_token(user_api_client, customer_user):
content = get_graphql_content(response)
errors = content["data"]["setPassword"]["errors"]
assert errors[0]["message"] == INVALID_TOKEN
- assert errors[0]["code"] == AccountErrorCode.INVALID_USER_TOKEN.name
+ assert errors[0]["code"] == CommonErrorCode.INVALID_TOKEN.name
def test_set_password_invalid_email(user_api_client):