diff options
| author | Tom Christie | 2012-10-17 15:23:36 +0100 | 
|---|---|---|
| committer | Tom Christie | 2012-10-17 15:23:36 +0100 | 
| commit | b78872b7dbb55f1aa2d21f15fbb952f0c7156326 (patch) | |
| tree | 48a6a5568ec91ea52d952caddbed557dc446ad59 /rest_framework/exceptions.py | |
| parent | a4d500ba107466e8d44a82ed8ca632a3ea81a016 (diff) | |
| download | django-rest-framework-b78872b7dbb55f1aa2d21f15fbb952f0c7156326.tar.bz2 | |
Use two seperate exceptions - `AuthenticationFailed`, and `NotAuthenticated`
Cleaner seperation of exception and resulting HTTP response.
Should result in more obvious error messages.
Diffstat (limited to 'rest_framework/exceptions.py')
| -rw-r--r-- | rest_framework/exceptions.py | 12 | 
1 files changed, 10 insertions, 2 deletions
| diff --git a/rest_framework/exceptions.py b/rest_framework/exceptions.py index 2461cacd..6ae0c95c 100644 --- a/rest_framework/exceptions.py +++ b/rest_framework/exceptions.py @@ -23,9 +23,17 @@ class ParseError(APIException):          self.detail = detail or self.default_detail -class Unauthenticated(APIException): +class AuthenticationFailed(APIException):      status_code = status.HTTP_401_UNAUTHORIZED -    default_detail = 'Incorrect or absent authentication credentials.' +    default_detail = 'Incorrect authentication credentials.' + +    def __init__(self, detail=None): +        self.detail = detail or self.default_detail + + +class NotAuthenticated(APIException): +    status_code = status.HTTP_401_UNAUTHORIZED +    default_detail = 'Authentication credentials were not provided.'      def __init__(self, detail=None):          self.detail = detail or self.default_detail | 
