@@ -34,7 +34,8 @@ def view_my_profile(update, context):
34
34
return
35
35
36
36
response = fpapi .get_current_user_profile (token = token )
37
- _assert_not_error (response )
37
+ if _is_error (response ):
38
+ raise ConnectionError ("Could not get current profile" ) # TODO handle errors better
38
39
user_info_view = views .UserProfile (response ).display ()
39
40
update .effective_message .reply_text (text = user_info_view )
40
41
@@ -187,7 +188,8 @@ def _get_posts(context, payload):
187
188
# keep a copy of post_payload in user_data for future calls - TODO is it used?
188
189
context .user_data [user_data .VIEW_POST_PAYLOAD ] = payload
189
190
posts = fpapi .get_posts (payload )
190
- _assert_not_error (posts )
191
+ if _is_error (posts ):
192
+ raise ConnectionError ("Could not get posts" ) # TODO handle errors better
191
193
return posts
192
194
193
195
@@ -356,7 +358,8 @@ def _get_real_post_id(context, user_choice):
356
358
357
359
def _show_user_single_post (update , context , post_id ):
358
360
post = fpapi .get_post (post_id )
359
- _assert_not_error (post )
361
+ if _is_error (post ):
362
+ raise ConnectionError ("Could not get post" ) # TODO handle errors better
360
363
reply_text = views .Post (post_json = post ).display ()
361
364
util .reply (
362
365
update = update ,
@@ -366,9 +369,8 @@ def _show_user_single_post(update, context, post_id):
366
369
)
367
370
368
371
369
- def _assert_not_error (post ):
370
- if isinstance (post , fpapi .Error ): # TODO handle error better
371
- raise ConnectionError ("Could not get post" )
372
+ def _is_error (post ):
373
+ return isinstance (post , fpapi .Error )
372
374
373
375
374
376
def _get_header_message_with_categories (context ):
@@ -383,7 +385,6 @@ def _get_header_message_user_posts(context):
383
385
return f"Page { page } of your posts"
384
386
385
387
386
-
387
388
def view_author_profile (update , context ):
388
389
post_id = context .user_data .get (user_data .VIEW_POST_ID )
389
390
if post_id is None :
@@ -409,10 +410,12 @@ def handle_go_back_view_author(update, context):
409
410
410
411
def _get_author_profile_from_post_id (post_id ):
411
412
raw_post = fpapi .get_post (post_id )
412
- _assert_not_error (raw_post )
413
+ if _is_error (raw_post ):
414
+ raise ConnectionError ("Could not get post" ) # TODO handle errors better
413
415
post = views .Post (post_json = raw_post )
414
416
response = fpapi .get_user_profile (user_id = post .author_id )
415
- _assert_not_error (response )
417
+ if _is_error (response ):
418
+ raise ConnectionError ("Could not get user profile" ) # TODO handle errors better
416
419
return views .UserProfile (response )
417
420
418
421
0 commit comments