use crate::types::ApiErrorBody;
#[derive(Debug, thiserror::Error)]
pub enum BankrError {
#[error("HTTP transport error: {0}")]
Transport(String),
#[error("API error (HTTP {status}): {body}")]
Api {
status: u16,
body: ApiErrorBody,
},
#[error("Deserialization error: {0}")]
Deserialization(String),
#[error("Job polling timed out after {attempts} attempts")]
PollTimeout {
attempts: u32,
},
#[error("Job failed: {message}")]
JobFailed {
message: String,
},
#[error("Job was cancelled")]
JobCancelled,
#[error("Configuration error: {0}")]
Config(String),
}
impl std::fmt::Display for ApiErrorBody {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(ref msg) = self.message {
write!(f, "{msg}")
} else if let Some(ref err) = self.error {
write!(f, "{err}")
} else {
write!(f, "(no details)")
}
}
}