use rustls::pki_types::InvalidDnsNameError;
use tokio::time::error::Elapsed;
use std::fmt;
use url::ParseError;
use crate::StreamCheckError;
#[derive(Debug)]
pub struct RequestError {
details: String,
}
impl RequestError {
pub fn new(details: &str) -> Self {
RequestError {
details: details.to_string(),
}
}
}
impl fmt::Display for RequestError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "RequestError: {}", self.details)
}
}
impl From<reqwest::Error> for RequestError {
fn from(value: reqwest::Error) -> Self {
RequestError {
details: format!("reqwest::Error {}", value),
}
}
}
impl From<reqwest::header::ToStrError> for RequestError {
fn from(_value: reqwest::header::ToStrError) -> Self {
RequestError {
details: String::from("reqwest::header::ToStrError"),
}
}
}
impl From<serde_json::Error> for RequestError {
fn from(value: serde_json::Error) -> Self {
RequestError {
details: format!("serde_json::Error {}", value),
}
}
}
impl From<ParseError> for RequestError {
fn from(value: ParseError) -> Self {
RequestError {
details: format!("ParseError {}", value),
}
}
}
impl From<std::io::Error> for RequestError {
fn from(value: std::io::Error) -> Self {
RequestError {
details: format!("std::io::Error {}", value),
}
}
}
impl From<StreamCheckError> for RequestError {
fn from(value: StreamCheckError) -> Self {
RequestError {
details: format!("StreamCheckError {}", value),
}
}
}
impl From<InvalidDnsNameError> for RequestError {
fn from(value: InvalidDnsNameError) -> Self {
RequestError {
details: format!("InvalidDnsNameError {}", value),
}
}
}
impl From<Elapsed> for RequestError {
fn from(value: Elapsed) -> Self {
RequestError {
details: format!("Elapsed {}", value),
}
}
}