Przeglądaj źródła

better exception message for request

Guénaël Muller 6 lat temu
rodzic
commit
df91e6b47a
2 zmienionych plików z 10 dodań i 7 usunięć
  1. 3 0
      tracim/exceptions.py
  2. 7 7
      tracim/lib/utils/request.py

+ 3 - 0
tracim/exceptions.py Wyświetl plik

@@ -94,4 +94,7 @@ class WrongUserPassword(TracimException):
94 94
 
95 95
 
96 96
 class UserDoesNotExist(TracimException):
97
+    pass
98
+
99
+class UserNotFoundInTracimRequest(TracimException):
97 100
     pass

+ 7 - 7
tracim/lib/utils/request.py Wyświetl plik

@@ -7,6 +7,7 @@ from sqlalchemy.orm.exc import NoResultFound
7 7
 
8 8
 
9 9
 from tracim.exceptions import NotAuthentificated
10
+from tracim.exceptions import UserNotFoundInTracimRequest
10 11
 from tracim.exceptions import UserDoesNotExist
11 12
 from tracim.exceptions import WorkspaceNotFound
12 13
 from tracim.exceptions import ImmutableAttribute
@@ -144,10 +145,10 @@ def get_candidate_user(
144 145
         if 'user_id' in request.matchdict:
145 146
             login = request.matchdict['user_id']
146 147
         if not login:
147
-            raise UserDoesNotExist('no user_id found, incorrect request ?')
148
+            raise UserNotFoundInTracimRequest('You request a candidate user but the context not permit to found one')  # nopep8
148 149
         user = uapi.get_one(login)
149
-    except NoResultFound:
150
-        raise NotAuthentificated('User not found')
150
+    except UserNotFoundInTracimRequest as exc:
151
+        raise UserDoesNotExist('User {} not found'.format(login)) from exc
151 152
     return user
152 153
 
153 154
 
@@ -164,11 +165,10 @@ def get_auth_safe_user(
164 165
     try:
165 166
         login = request.authenticated_userid
166 167
         if not login:
167
-            raise NotAuthentificated('not authenticated user_id,'
168
-                                     'Failed Authentification ?')
168
+            raise UserNotFoundInTracimRequest('You request a current user but the context not permit to found one')  # nopep8
169 169
         user = uapi.get_one_by_email(login)
170
-    except NoResultFound:
171
-        raise NotAuthentificated('User not found')
170
+    except (UserDoesNotExist, UserNotFoundInTracimRequest) as exc:
171
+        raise NotAuthentificated('User {} not found'.format(login)) from exc
172 172
     return user
173 173
 
174 174