@@ -6,6 +6,7 @@ use reqwest::header::USER_AGENT;
6
6
use crate :: http:: { RobotsTxtClient , DEFAULT_USER_AGENT } ;
7
7
use crate :: parser:: { ParseResult , parse_fetched_robots_txt} ;
8
8
use crate :: model:: FetchedRobotsTxt ;
9
+ use crate :: model:: { RobotparserError , ErrorKind } ;
9
10
use std:: pin:: Pin ;
10
11
use futures:: task:: { Context , Poll } ;
11
12
use futures:: Future ;
@@ -15,10 +16,10 @@ use futures::future::ok as future_ok;
15
16
type FetchFuture = Box < dyn Future < Output =Result < ( ResponseInfo , String ) , Error > > > ;
16
17
17
18
impl RobotsTxtClient for Client {
18
- type Result = RobotsTxtResponse ;
19
+ type Result = Result < RobotsTxtResponse , RobotparserError > ;
19
20
fn fetch_robots_txt ( & self , origin : Origin ) -> Self :: Result {
20
21
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 ) } ) ? ;
22
23
let mut request = Request :: new ( Method :: GET , url) ;
23
24
let _ = request. headers_mut ( ) . insert ( USER_AGENT , HeaderValue :: from_static ( DEFAULT_USER_AGENT ) ) ;
24
25
let response = self
@@ -30,10 +31,10 @@ impl RobotsTxtClient for Client {
30
31
} ) ;
31
32
} ) ;
32
33
let response: Pin < Box < dyn Future < Output =Result < ( ResponseInfo , String ) , Error > > > > = Box :: pin ( response) ;
33
- return RobotsTxtResponse {
34
+ Ok ( RobotsTxtResponse {
34
35
origin,
35
36
response,
36
- }
37
+ } )
37
38
}
38
39
}
39
40
@@ -73,4 +74,4 @@ impl Future for RobotsTxtResponse {
73
74
} ,
74
75
}
75
76
}
76
- }
77
+ }
0 commit comments