robotparser-rs/src/model/errors.rs
Laurent Arnoud df49f6bcf0
Error handling (#24)
* Add test when url is invalid and panic

* Initial error handling

ref https://github.com/messense/robotparser-rs/issues/22

* Rename ErrorKind::HttpClient => ErrorKind::Http

* Implement std::error::Error and rename to Error
2020-03-08 20:33:34 +08:00

23 lines
445 B
Rust

use std::fmt;
#[derive(Debug)]
pub struct Error {
pub kind: ErrorKind,
}
#[derive(Debug)]
pub enum ErrorKind {
Url(url::ParseError),
Http(reqwest::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.kind {
ErrorKind::Url(ref err) => err.fmt(f),
ErrorKind::Http(ref err) => err.fmt(f),
}
}
}
impl std::error::Error for Error {}