use conjure_error::SerializableError;
use http::StatusCode;
use std::error::Error;
use std::fmt;
use std::time::Duration;
#[derive(Debug)]
pub struct RemoteError {
pub(crate) status: StatusCode,
pub(crate) error: Option<SerializableError>,
}
impl fmt::Display for RemoteError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.error() {
Some(error) => write!(
fmt,
"remote error: {} ({}) with instance ID {}",
error.error_code(),
error.error_name(),
error.error_instance_id()
),
None => write!(fmt, "remote error: {}", self.status),
}
}
}
impl Error for RemoteError {}
impl RemoteError {
pub fn status(&self) -> &StatusCode {
&self.status
}
pub fn error(&self) -> Option<&SerializableError> {
self.error.as_ref()
}
}
#[derive(Debug)]
pub struct ThrottledError {
pub(crate) retry_after: Option<Duration>,
}
impl fmt::Display for ThrottledError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.write_str("got a 429 from the remote service")
}
}
impl Error for ThrottledError {}
#[derive(Debug)]
pub struct UnavailableError(pub(crate) ());
impl fmt::Display for UnavailableError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.write_str("got a 503 from the remote service")
}
}
impl Error for UnavailableError {}