Передать ошибки сериализатора как ответ в формате списка
Я использую graphene_django
рядом rest_framework serializers
, Когда я получаю проблему проверки, я получаю сообщение об ошибке следующим образом
"{'email': [ErrorDetail(string='user with this Email Address already exists.', code='unique')]}",
Как я могу передать ошибку в списке так, как если бы пароль не совпадал?
вот как я сейчас делаю
class Register(graphene.Mutation):
class Arguments:
email = graphene.String(required=True)
password = graphene.String(required=True)
password_repeat = graphene.String(required=True)
user = graphene.Field(UserQuery)
token = graphene.String()
success = graphene.Boolean()
errors = graphene.List(graphene.String)
@staticmethod
def mutate(self, info, email, password, password_repeat):
if password == password_repeat:
try:
serializer = RegistrationSerializer(data={'email': email, 'password': password, 'is_confirmed': False})
print('#########Serializer########', serializer)
if serializer.is_valid(raise_exception=True):
print('serializer is valid')
user = serializer.save()
auth = authenticate(username=email, password=password)
login(info.context, auth)
return Register(success=True, user=user, token=get_token(auth))
print('############serializer errors##########', serializer.errors)
return Register(success=False, token=None, errors=['email/password', 'Unable to login'])
except ValidationError as e:
print("validation error", e)
return Register(success=False, errors=[e])
return Register(success=False, errors=['password', 'password is not matching'])