Skip to content

Commit b2525b5

Browse files
committed
Implement std::error::Error and rename to Error
1 parent df30fe6 commit b2525b5

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

src/http/reqwest/async_reqwest.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
use reqwest::{Client, Request};
2-
use reqwest::{Method, Error};
2+
use reqwest::Method;
3+
use reqwest::Error as ReqwestError;
34
use reqwest::header::HeaderValue;
45
use url::{Origin, Url};
56
use reqwest::header::USER_AGENT;
67
use crate::http::{RobotsTxtClient, DEFAULT_USER_AGENT};
78
use crate::parser::{ParseResult, parse_fetched_robots_txt};
89
use crate::model::FetchedRobotsTxt;
9-
use crate::model::{RobotparserError, ErrorKind};
10+
use crate::model::{Error, ErrorKind};
1011
use std::pin::Pin;
1112
use futures::task::{Context, Poll};
1213
use futures::Future;
1314
use futures::future::TryFutureExt;
1415
use futures::future::ok as future_ok;
1516

16-
type FetchFuture = Box<dyn Future<Output=Result<(ResponseInfo, String), Error>>>;
17+
type FetchFuture = Box<dyn Future<Output=Result<(ResponseInfo, String), ReqwestError>>>;
1718

1819
impl RobotsTxtClient for Client {
19-
type Result = Result<RobotsTxtResponse, RobotparserError>;
20+
type Result = Result<RobotsTxtResponse, Error>;
2021
fn fetch_robots_txt(&self, origin: Origin) -> Self::Result {
2122
let url = format!("{}/robots.txt", origin.unicode_serialization());
22-
let url = Url::parse(&url).map_err(|err| RobotparserError {kind: ErrorKind::Url(err)})?;
23+
let url = Url::parse(&url).map_err(|err| Error {kind: ErrorKind::Url(err)})?;
2324
let mut request = Request::new(Method::GET, url);
2425
let _ = request.headers_mut().insert(USER_AGENT, HeaderValue::from_static(DEFAULT_USER_AGENT));
2526
let response = self
@@ -30,7 +31,7 @@ impl RobotsTxtClient for Client {
3031
return future_ok((response_info, response_text));
3132
});
3233
});
33-
let response: Pin<Box<dyn Future<Output=Result<(ResponseInfo, String), Error>>>> = Box::pin(response);
34+
let response: Pin<Box<dyn Future<Output=Result<(ResponseInfo, String), ReqwestError>>>> = Box::pin(response);
3435
Ok(RobotsTxtResponse {
3536
origin,
3637
response,
@@ -56,7 +57,7 @@ impl RobotsTxtResponse {
5657
}
5758

5859
impl Future for RobotsTxtResponse {
59-
type Output = Result<ParseResult<FetchedRobotsTxt>, Error>;
60+
type Output = Result<ParseResult<FetchedRobotsTxt>, ReqwestError>;
6061

6162
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
6263
let self_mut = self.get_mut();

src/http/reqwest/sync_reqwest.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ use reqwest::header::USER_AGENT;
66
use crate::http::{RobotsTxtClient, DEFAULT_USER_AGENT};
77
use crate::parser::{ParseResult, parse_fetched_robots_txt};
88
use crate::model::FetchedRobotsTxt;
9-
use crate::model::{RobotparserError, ErrorKind};
9+
use crate::model::{Error, ErrorKind};
1010

1111
impl RobotsTxtClient for Client {
12-
type Result = Result<ParseResult<FetchedRobotsTxt>, RobotparserError>;
12+
type Result = Result<ParseResult<FetchedRobotsTxt>, Error>;
1313
fn fetch_robots_txt(&self, origin: Origin) -> Self::Result {
1414
let url = format!("{}/robots.txt", origin.unicode_serialization());
15-
let url = Url::parse(&url).map_err(|err| RobotparserError {kind: ErrorKind::Url(err)})?;
15+
let url = Url::parse(&url).map_err(|err| Error {kind: ErrorKind::Url(err)})?;
1616
let mut request = Request::new(Method::GET, url);
1717
let _ = request.headers_mut().insert(USER_AGENT, HeaderValue::from_static(DEFAULT_USER_AGENT));
18-
let response = self.execute(request).map_err(|err| RobotparserError {kind: ErrorKind::Http(err)})?;
18+
let response = self.execute(request).map_err(|err| Error {kind: ErrorKind::Http(err)})?;
1919
let status_code = response.status().as_u16();
20-
let text = response.text().map_err(|err| RobotparserError {kind: ErrorKind::Http(err)})?;
20+
let text = response.text().map_err(|err| Error {kind: ErrorKind::Http(err)})?;
2121
let robots_txt = parse_fetched_robots_txt(origin, status_code, &text);
2222
return Ok(robots_txt);
2323
}

src/model.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ pub use self::robots_txt::RobotsTxt;
1616
mod path;
1717
pub (crate) use self::path::Path;
1818
mod errors;
19-
pub use self::errors::{RobotparserError, ErrorKind};
19+
pub use self::errors::{Error, ErrorKind};

src/model/errors.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22

33
#[derive(Debug)]
4-
pub struct RobotparserError {
4+
pub struct Error {
55
pub kind: ErrorKind,
66
}
77

@@ -11,11 +11,13 @@ pub enum ErrorKind {
1111
Http(reqwest::Error),
1212
}
1313

14-
impl fmt::Display for RobotparserError {
14+
impl fmt::Display for Error {
1515
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1616
match self.kind {
1717
ErrorKind::Url(ref err) => err.fmt(f),
1818
ErrorKind::Http(ref err) => err.fmt(f),
1919
}
2020
}
2121
}
22+
23+
impl std::error::Error for Error {}

0 commit comments

Comments
 (0)