Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/rest_framework_simplejwt/exceptions.py: 63%

22 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1from django.utils.translation import gettext_lazy as _ 

2from rest_framework import exceptions, status 

3 

4 

5class TokenError(Exception): 

6 pass 

7 

8 

9class TokenBackendError(Exception): 

10 pass 

11 

12 

13class DetailDictMixin: 

14 def __init__(self, detail=None, code=None): 

15 """ 

16 Builds a detail dictionary for the error to give more information to API 

17 users. 

18 """ 

19 detail_dict = {"detail": self.default_detail, "code": self.default_code} 

20 

21 if isinstance(detail, dict): 

22 detail_dict.update(detail) 

23 elif detail is not None: 

24 detail_dict["detail"] = detail 

25 

26 if code is not None: 

27 detail_dict["code"] = code 

28 

29 super().__init__(detail_dict) 

30 

31 

32class AuthenticationFailed(DetailDictMixin, exceptions.AuthenticationFailed): 

33 pass 

34 

35 

36class InvalidToken(AuthenticationFailed): 

37 status_code = status.HTTP_401_UNAUTHORIZED 

38 default_detail = _("Token is invalid or expired") 

39 default_code = "token_not_valid"