#[derive(Debug)]
pub enum RequestError {
ConfigurationError(String),
CommunicationError,
AuthenticationError,
AuthorizationError,
BadSymbolError(String),
BadRequestError,
BadResponseError,
RequestThrottled,
Unsupported,
}
pub type RequestResult<T> = Result<T, RequestError>;
impl RequestError {
#[allow(ellipsis_inclusive_range_patterns)]
pub fn from_u16(code: u16) -> Option<Self> {
match code {
100...299 => None,
401 | 407 => Some(RequestError::AuthenticationError),
403 | 451 => Some(RequestError::AuthorizationError),
400 | 404...406 | 411...417 | 426...428 | 431 => Some(RequestError::BadRequestError),
429 => Some(RequestError::RequestThrottled),
501 => Some(RequestError::Unsupported),
505 | 506 => Some(RequestError::BadRequestError),
511 => Some(RequestError::AuthorizationError),
_ => Some(RequestError::CommunicationError),
}
}
}