@@ -34,7 +34,8 @@ def view_my_profile(update, context):
3434 return
3535
3636 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
3839 user_info_view = views .UserProfile (response ).display ()
3940 update .effective_message .reply_text (text = user_info_view )
4041
@@ -187,7 +188,8 @@ def _get_posts(context, payload):
187188 # keep a copy of post_payload in user_data for future calls - TODO is it used?
188189 context .user_data [user_data .VIEW_POST_PAYLOAD ] = payload
189190 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
191193 return posts
192194
193195
@@ -356,7 +358,8 @@ def _get_real_post_id(context, user_choice):
356358
357359def _show_user_single_post (update , context , post_id ):
358360 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
360363 reply_text = views .Post (post_json = post ).display ()
361364 util .reply (
362365 update = update ,
@@ -366,9 +369,8 @@ def _show_user_single_post(update, context, post_id):
366369 )
367370
368371
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 )
372374
373375
374376def _get_header_message_with_categories (context ):
@@ -383,7 +385,6 @@ def _get_header_message_user_posts(context):
383385 return f"Page { page } of your posts"
384386
385387
386-
387388def view_author_profile (update , context ):
388389 post_id = context .user_data .get (user_data .VIEW_POST_ID )
389390 if post_id is None :
@@ -409,10 +410,12 @@ def handle_go_back_view_author(update, context):
409410
410411def _get_author_profile_from_post_id (post_id ):
411412 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
413415 post = views .Post (post_json = raw_post )
414416 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
416419 return views .UserProfile (response )
417420
418421
0 commit comments