1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
use crate::{ http::{self, header::HeaderName, Response, StatusCode}, url, FromContentError, ToContentError, }; use derive_more::{Constructor, Display, From}; use std::fmt::{Debug, Display}; pub trait Error = From<url::ParseError> + From<http::Error> + From<ToContentError> + From<FromContentError> + From<Unexpected> + Display + Debug; #[derive(Debug, Display, Constructor)] #[display(fmt = "Unexpected: {}", typ)] pub struct Unexpected { typ: UnexpectedType, resp: Response<Vec<u8>>, } #[derive(Debug, Display, From)] pub enum UnexpectedType { #[display(fmt = "status code should be {}", expect)] StatusCode { expect: StatusCode }, #[display(fmt = "value of header '{}' is unexpected: {}", header_name, msg)] Header { header_name: HeaderName, msg: String, }, } impl std::error::Error for Unexpected {} impl std::error::Error for UnexpectedType {}