Skip to content

Commit 0c48c66

Browse files
committed
- fix:issue #2: change exception message
1 parent 083ab0b commit 0c48c66

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

api/authentication/serializers/login.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import jwt
2-
from rest_framework import serializers
2+
from rest_framework import serializers, exceptions
33
from django.contrib.auth import authenticate
44
from datetime import datetime, timedelta
55
from django.conf import settings
@@ -27,22 +27,20 @@ def validate(self, data):
2727
password = data.get("password", None)
2828

2929
if email is None:
30-
raise serializers.ValidationError(
30+
raise exceptions.ValidationError(
3131
{"success": False, "msg": "Email is required to login"}
3232
)
3333
if password is None:
34-
raise serializers.ValidationError(
34+
raise exceptions.ValidationError(
3535
{"success": False, "msg": "Password is required to log in."}
3636
)
3737
user = authenticate(username=email, password=password)
3838

3939
if user is None:
40-
raise serializers.ValidationError(
41-
{"success": False, "msg": "Wrong credentials"}
42-
)
40+
raise exceptions.AuthenticationFailed({"success": False, "msg": "Wrong credentials"})
4341

4442
if not user.is_active:
45-
raise serializers.ValidationError(
43+
raise exceptions.ValidationError(
4644
{"success": False, "msg": "User is not active"}
4745
)
4846

0 commit comments

Comments
 (0)