Browse Source

better exception message for request

Guénaël Muller 6 years ago
parent
commit
df91e6b47a
2 changed files with 10 additions and 7 deletions
  1. 3 0
      tracim/exceptions.py
  2. 7 7
      tracim/lib/utils/request.py

+ 3 - 0
tracim/exceptions.py View File

94
 
94
 
95
 
95
 
96
 class UserDoesNotExist(TracimException):
96
 class UserDoesNotExist(TracimException):
97
+    pass
98
+
99
+class UserNotFoundInTracimRequest(TracimException):
97
     pass
100
     pass

+ 7 - 7
tracim/lib/utils/request.py View File

7
 
7
 
8
 
8
 
9
 from tracim.exceptions import NotAuthentificated
9
 from tracim.exceptions import NotAuthentificated
10
+from tracim.exceptions import UserNotFoundInTracimRequest
10
 from tracim.exceptions import UserDoesNotExist
11
 from tracim.exceptions import UserDoesNotExist
11
 from tracim.exceptions import WorkspaceNotFound
12
 from tracim.exceptions import WorkspaceNotFound
12
 from tracim.exceptions import ImmutableAttribute
13
 from tracim.exceptions import ImmutableAttribute
144
         if 'user_id' in request.matchdict:
145
         if 'user_id' in request.matchdict:
145
             login = request.matchdict['user_id']
146
             login = request.matchdict['user_id']
146
         if not login:
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
         user = uapi.get_one(login)
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
     return user
152
     return user
152
 
153
 
153
 
154
 
164
     try:
165
     try:
165
         login = request.authenticated_userid
166
         login = request.authenticated_userid
166
         if not login:
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
         user = uapi.get_one_by_email(login)
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
     return user
172
     return user
173
 
173
 
174
 
174