@@ -42,10 +42,7 @@ def cohort(cohort_id):
4242 response_obj = None
4343
4444 if not user :
45- response_obj = {
46- 'message' : 'Encountered an error while attempting to identify this user.'
47- }
48- code = 500
45+ raise Exception ('Encountered an error while attempting to identify this user.' )
4946 else :
5047 if cohort_id <= 0 :
5148 logger .warn ("[WARNING] Invalid cohort ID {}" .format (str (cohort_id )))
@@ -62,12 +59,8 @@ def cohort(cohort_id):
6259 cohort_info = edit_cohort (cohort_id , user , delete = (request .method == 'DELETE' ))
6360
6461 if cohort_info :
65- response_obj ['data' ] = cohort_info
66-
67- if 'message' in cohort_info :
68- code = 400
69- else :
70- code = 200
62+ response_obj = {'data' : cohort_info }
63+ code = 400 if 'message' in cohort_info else 200
7164 else :
7265 response_obj = {
7366 'message' : "Cohort ID {} was not found." .format (str (cohort_id ))
@@ -111,36 +104,23 @@ def cohorts():
111104 user = validate_user (user_info ['email' ])
112105
113106 if not user :
114- response_obj = {
115- 'code' : 500 ,
116- 'message' : 'Encountered an error while attempting to identify this user.'
117- }
118- code = 500
107+ raise Exception ('Encountered an error while attempting to identify this user.' )
119108 else :
120109 st_logger .write_text_log_entry (log_name , user_activity_message .format (user_info ['email' ], request .method , request .full_path ))
121- if request .method == 'GET' :
122- info = get_cohorts (user_info ['email' ])
123- else :
124- info = create_cohort (user )
110+ info = get_cohorts (user_info ['email' ]) if request .method == 'GET' else create_cohort (user )
125111
126112 if info :
127- response_obj = {}
128-
129- if 'message' in info :
130- code = 400
131- else :
132- code = 200
113+ response_obj = {
114+ 'data' : info
115+ }
133116
134- response_obj [ 'data' ] = info
117+ code = 400 if 'message' in info else 200
135118
136119 # Lack of a valid object means something went wrong on the server
137120 else :
138- response_obj = {
139- 'message' : "Error while attempting to {}." .format (
140- 'retrieve the cohort list' if request .method == 'GET' else 'create this cohort'
141- )
142- }
143- code = 500
121+ raise Exception ("Invalid response while attempting to {}." .format (
122+ 'retrieve the cohort list' if request .method == 'GET' else 'create this cohort'
123+ ))
144124
145125 except UserValidationException as e :
146126 response_obj = {
@@ -161,7 +141,7 @@ def cohorts():
161141 response_obj ['code' ] = code
162142 response = jsonify (response_obj )
163143 response .status_code = code
164-
144+
165145 return response
166146
167147
@@ -180,10 +160,7 @@ def cohort_file_manifest(cohort_id):
180160 user = validate_user (user_info ['email' ], cohort_id )
181161
182162 if not user :
183- response_obj = {
184- 'message' : 'Encountered an error while attempting to identify this user.'
185- }
186- code = 500
163+ raise Exception ('Encountered an error while attempting to identify this user.' )
187164 else :
188165 if cohort_id <= 0 :
189166 logger .warn ("[WARNING] Invalid cohort ID {}" .format (str (cohort_id )))
@@ -205,10 +182,7 @@ def cohort_file_manifest(cohort_id):
205182 'data' : file_manifest
206183 }
207184 else :
208- response_obj = {
209- 'message' : "Error while attempting to retrieve file manifest for cohort {}." .format (str (cohort_id ))
210- }
211- code = 500
185+ raise Exception ("Invalid response while attempting to retrieve file manifest for cohort {}." .format (str (cohort_id )))
212186
213187 except UserValidationException as e :
214188 response_obj = {
@@ -256,11 +230,8 @@ def cohort_preview():
256230
257231 # Lack of a valid object means something went wrong on the server
258232 else :
259- response_obj = {
260- 'message' : "Error while attempting to retrieve case and sample counts for these filters."
261- }
262- code = 500
263-
233+ raise Exception ("Invalid response while attempting to retrieve case and sample counts for these filters." )
234+
264235 except Exception as e :
265236 logger .exception (e )
266237 response_obj = {
0 commit comments