Skip to main content

forge_system_one/
error.rs

1/// Why a System One call failed; the tool layer words its message from
2/// these variants.
3#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
4pub enum SystemOneError {
5    #[error("System One request failed: {0}")]
6    Transport(String),
7    #[error("System One request timed out")]
8    Timeout,
9    #[error("System One returned HTTP {status}: {body}")]
10    Http { status: u16, body: String },
11    #[error("System One returned an invalid answer: {0}")]
12    InvalidResponse(String),
13}
14
15#[cfg(test)]
16mod tests {
17    use super::*;
18
19    #[test]
20    fn display_carries_the_failure_shape() {
21        assert_eq!(SystemOneError::Timeout.to_string(), "System One request timed out");
22        assert_eq!(
23            SystemOneError::Transport("boom".to_owned()).to_string(),
24            "System One request failed: boom"
25        );
26        assert_eq!(
27            SystemOneError::Http { status: 422, body: "detail".to_owned() }.to_string(),
28            "System One returned HTTP 422: detail"
29        );
30        assert_eq!(
31            SystemOneError::InvalidResponse("keys".to_owned()).to_string(),
32            "System One returned an invalid answer: keys"
33        );
34    }
35}