@@ -6,6 +6,7 @@ use reqwest::header::USER_AGENT;
66use crate :: http:: { RobotsTxtClient , DEFAULT_USER_AGENT } ;
77use crate :: parser:: { ParseResult , parse_fetched_robots_txt} ;
88use crate :: model:: FetchedRobotsTxt ;
9+ use crate :: model:: { RobotparserError , ErrorKind } ;
910use std:: pin:: Pin ;
1011use futures:: task:: { Context , Poll } ;
1112use futures:: Future ;
@@ -15,10 +16,10 @@ use futures::future::ok as future_ok;
1516type FetchFuture = Box < dyn Future < Output =Result < ( ResponseInfo , String ) , Error > > > ;
1617
1718impl RobotsTxtClient for Client {
18- type Result = RobotsTxtResponse ;
19+ type Result = Result < RobotsTxtResponse , RobotparserError > ;
1920 fn fetch_robots_txt ( & self , origin : Origin ) -> Self :: Result {
2021 let url = format ! ( "{}/robots.txt" , origin. unicode_serialization( ) ) ;
21- let url = Url :: parse ( & url) . expect ( "Unable to parse robots.txt url" ) ;
22+ let url = Url :: parse ( & url) . map_err ( |err| RobotparserError { kind : ErrorKind :: Url ( err ) } ) ? ;
2223 let mut request = Request :: new ( Method :: GET , url) ;
2324 let _ = request. headers_mut ( ) . insert ( USER_AGENT , HeaderValue :: from_static ( DEFAULT_USER_AGENT ) ) ;
2425 let response = self
@@ -30,10 +31,10 @@ impl RobotsTxtClient for Client {
3031 } ) ;
3132 } ) ;
3233 let response: Pin < Box < dyn Future < Output =Result < ( ResponseInfo , String ) , Error > > > > = Box :: pin ( response) ;
33- return RobotsTxtResponse {
34+ Ok ( RobotsTxtResponse {
3435 origin,
3536 response,
36- }
37+ } )
3738 }
3839}
3940
@@ -73,4 +74,4 @@ impl Future for RobotsTxtResponse {
7374 } ,
7475 }
7576 }
76- }
77+ }
0 commit comments