From 24b49f8cc50862733449a3b7a53cfe670e66edd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Lang?= Date: Fri, 12 Dec 2014 14:34:14 -0300 Subject: [PATCH] Raise 401 error when login failed Authtoken was raising a 400 error code when trying to log in with invalid username/password when it should raise a 401 error (Unauthorized) --- rest_framework/authtoken/serializers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest_framework/authtoken/serializers.py b/rest_framework/authtoken/serializers.py index f31dded17..7a8ce64b1 100644 --- a/rest_framework/authtoken/serializers.py +++ b/rest_framework/authtoken/serializers.py @@ -18,10 +18,10 @@ class AuthTokenSerializer(serializers.Serializer): if user: if not user.is_active: msg = _('User account is disabled.') - raise exceptions.ValidationError(msg) + raise exceptions.AuthenticationFailed(msg) else: msg = _('Unable to log in with provided credentials.') - raise exceptions.ValidationError(msg) + raise exceptions.AuthenticationFailed(msg) else: msg = _('Must include "username" and "password"') raise exceptions.ValidationError(msg)