@@ -16,7 +16,7 @@ use crate::service::file_service::FileService;
1616use crate :: service:: settings_service:: SettingsService ;
1717use crate :: service:: telegram_api:: send_new_episode_notification;
1818use crate :: utils:: environment_variables:: is_env_var_present_and_true;
19- use crate :: utils:: error:: { map_db_error, CustomError , CustomErrorInner } ;
19+ use crate :: utils:: error:: { map_db_error, map_reqwest_error , CustomError , CustomErrorInner } ;
2020use crate :: utils:: podcast_builder:: PodcastBuilder ;
2121use crate :: utils:: reqwest_client:: get_sync_client;
2222use diesel:: { ExpressionMethods , OptionalExtension , QueryDsl , RunQueryDsl } ;
@@ -100,10 +100,11 @@ impl PodcastEpisodeService {
100100 }
101101
102102 // Used for creating/updating podcasts
103- pub fn insert_podcast_episodes ( podcast : Podcast ) -> Result < Vec < PodcastEpisode > , CustomError > {
103+ pub fn insert_podcast_episodes ( podcast : & Podcast ) -> Result < Vec < PodcastEpisode > , CustomError > {
104104 let is_redirected = Arc :: new ( Mutex :: new ( false ) ) ; // Variable to store the redirection status
105105
106- let returned_data_from_podcast_insert = Self :: do_request_to_podcast_server ( podcast. clone ( ) ) ;
106+ let returned_data_from_podcast_insert = Self :: do_request_to_podcast_server ( podcast. clone
107+ ( ) ) ?;
107108
108109 let channel = Channel :: read_from ( returned_data_from_podcast_insert. content . as_bytes ( ) ) ;
109110
@@ -122,13 +123,13 @@ impl PodcastEpisodeService {
122123 Self :: update_episodes_on_redirect ( channel. items ( ) ) ?;
123124 }
124125
125- Self :: handle_itunes_extension ( & podcast, & channel) ?;
126+ Self :: handle_itunes_extension ( podcast, & channel) ?;
126127
127128 Self :: update_podcast_fields ( channel. clone ( ) , podcast. id ) ?;
128129
129130 let mut podcast_inserted = Vec :: new ( ) ;
130131
131- Self :: handle_podcast_image_insert ( & podcast, & channel) ?;
132+ Self :: handle_podcast_image_insert ( podcast, & channel) ?;
132133
133134 for item in channel. items . iter ( ) {
134135 let itunes_ext = item. clone ( ) . itunes_ext ;
@@ -289,7 +290,8 @@ impl PodcastEpisodeService {
289290 let new_url = extension. new_feed_url . unwrap ( ) ;
290291 Podcast :: update_podcast_urls_on_redirect ( podcast. id , new_url) ;
291292
292- let returned_data_from_server = Self :: do_request_to_podcast_server ( podcast. clone ( ) ) ;
293+ let returned_data_from_server = Self :: do_request_to_podcast_server ( podcast. clone
294+ ( ) ) ?;
293295
294296 let channel =
295297 Channel :: read_from ( returned_data_from_server. content . as_bytes ( ) ) . unwrap ( ) ;
@@ -483,7 +485,7 @@ impl PodcastEpisodeService {
483485 PodcastEpisode :: get_podcast_episode_by_id ( id_num)
484486 }
485487
486- fn do_request_to_podcast_server ( podcast : Podcast ) -> RequestReturnType {
488+ fn do_request_to_podcast_server ( podcast : Podcast ) -> Result < RequestReturnType , CustomError > {
487489 let is_redirected = Arc :: new ( Mutex :: new ( false ) ) ; // Variable to store the redirection status
488490 let client = get_sync_client ( )
489491 . redirect ( Policy :: custom ( {
@@ -497,22 +499,23 @@ impl PodcastEpisodeService {
497499 }
498500 } ) )
499501 . build ( )
500- . unwrap ( ) ;
502+ . map_err ( map_reqwest_error ) ? ;
501503 let mut header_map = HeaderMap :: new ( ) ;
502504 header_map. append (
503505 ACCEPT ,
506+ // Safe as it is a standard header
504507 "application/rss+xml,application/xml" . parse ( ) . unwrap ( ) ,
505508 ) ;
506509 header_map. append ( "User-Agent" , COMMON_USER_AGENT . parse ( ) . unwrap ( ) ) ;
507510 let result = client
508511 . get ( podcast. clone ( ) . rssfeed )
509512 . headers ( header_map)
510513 . send ( )
511- . unwrap ( ) ;
514+ . map_err ( map_reqwest_error ) ? ;
512515 let url = result. url ( ) . clone ( ) . to_string ( ) ;
513- let content = result. text ( ) . unwrap ( ) . clone ( ) ;
516+ let content = result. text ( ) . map_err ( map_reqwest_error ) ? ;
514517
515- RequestReturnType { url, content }
518+ Ok ( RequestReturnType { url, content } )
516519 }
517520
518521 pub ( crate ) fn delete_podcast_episode_locally (
0 commit comments