1use crate::types::ApiErrorBody;
4
5#[derive(Debug, thiserror::Error)]
7pub enum BankrError {
8 #[error("HTTP transport error: {0}")]
10 Transport(String),
11
12 #[error("API error (HTTP {status}): {body}")]
14 Api {
15 status: u16,
17 body: ApiErrorBody,
19 },
20
21 #[error("Deserialization error: {0}")]
23 Deserialization(String),
24
25 #[error("Job polling timed out after {attempts} attempts")]
27 PollTimeout {
28 attempts: u32,
30 },
31
32 #[error("Job failed: {message}")]
34 JobFailed {
35 message: String,
37 },
38
39 #[error("Job was cancelled")]
41 JobCancelled,
42
43 #[error("Configuration error: {0}")]
45 Config(String),
46}
47
48impl std::fmt::Display for ApiErrorBody {
49 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50 if let Some(ref msg) = self.message {
51 write!(f, "{msg}")
52 } else if let Some(ref err) = self.error {
53 write!(f, "{err}")
54 } else {
55 write!(f, "(no details)")
56 }
57 }
58}