diff --git a/rest_framework_simplejwt/serializers.py b/rest_framework_simplejwt/serializers.py index 3dc318687..76501ee1f 100644 --- a/rest_framework_simplejwt/serializers.py +++ b/rest_framework_simplejwt/serializers.py @@ -7,6 +7,7 @@ from rest_framework import exceptions, serializers from rest_framework.exceptions import ValidationError +from .exceptions import TokenError from .models import TokenUser from .settings import api_settings from .tokens import RefreshToken, SlidingToken, Token, UntypedToken @@ -105,7 +106,10 @@ class TokenRefreshSerializer(serializers.Serializer): token_class = RefreshToken def validate(self, attrs: Dict[str, Any]) -> Dict[str, str]: - refresh = self.token_class(attrs["refresh"]) + try: + refresh = self.token_class(attrs["refresh"]) + except TokenError: + raise serializers.ValidationError("token is not valid") data = {"access": str(refresh.access_token)}