Skip to content

Commit 670b0b7

Browse files
committed
Use serializers.ValidationError
Per django rest framework docs, and to prevent confusion with Django's ValidationError, `serializers.ValidationError` is preferred to `exceptions.ValidationError`.
1 parent cadbfba commit 670b0b7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

rest_framework/authtoken/serializers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.contrib.auth import authenticate
22
from django.utils.translation import ugettext_lazy as _
33

4-
from rest_framework import exceptions, serializers
4+
from rest_framework import serializers
55

66

77
class AuthTokenSerializer(serializers.Serializer):
@@ -18,13 +18,13 @@ def validate(self, attrs):
1818
if user:
1919
if not user.is_active:
2020
msg = _('User account is disabled.')
21-
raise exceptions.ValidationError(msg)
21+
raise serializers.ValidationError(msg)
2222
else:
2323
msg = _('Unable to log in with provided credentials.')
24-
raise exceptions.ValidationError(msg)
24+
raise serializers.ValidationError(msg)
2525
else:
2626
msg = _('Must include "username" and "password".')
27-
raise exceptions.ValidationError(msg)
27+
raise serializers.ValidationError(msg)
2828

2929
attrs['user'] = user
3030
return attrs

0 commit comments

Comments
 (0)