conjure_runtime/
errors.rs1use conjure_error::SerializableError;
17use http::StatusCode;
18use std::error::Error;
19use std::fmt;
20use std::time::Duration;
21
22#[derive(Debug)]
24pub struct RemoteError {
25 pub(crate) status: StatusCode,
26 pub(crate) error: Option<SerializableError>,
27}
28
29impl fmt::Display for RemoteError {
30 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self.error() {
32 Some(error) => write!(
33 fmt,
34 "remote error: {} ({}) with instance ID {}",
35 error.error_code(),
36 error.error_name(),
37 error.error_instance_id()
38 ),
39 None => write!(fmt, "remote error: {}", self.status),
40 }
41 }
42}
43
44impl Error for RemoteError {}
45
46impl RemoteError {
47 pub fn status(&self) -> &StatusCode {
49 &self.status
50 }
51
52 pub fn error(&self) -> Option<&SerializableError> {
54 self.error.as_ref()
55 }
56}
57
58#[derive(Debug)]
60pub struct ThrottledError {
61 pub(crate) retry_after: Option<Duration>,
62}
63
64impl fmt::Display for ThrottledError {
65 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
66 fmt.write_str("got a 429 from the remote service")
67 }
68}
69
70impl Error for ThrottledError {}
71
72#[derive(Debug)]
74pub struct UnavailableError(pub(crate) ());
75
76impl fmt::Display for UnavailableError {
77 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
78 fmt.write_str("got a 503 from the remote service")
79 }
80}
81
82impl Error for UnavailableError {}