1use std::fmt;
4
5#[derive(Debug, Clone)]
7pub enum ClientError {
8 TranslationError(String),
10 NetworkError(String),
12 BackendError { status: u16, message: String },
14 ParseError(String),
16 Timeout {
18 elapsed_secs: u64,
20 timeout_secs: u64,
22 },
23 InvalidRequest(String),
25}
26
27impl fmt::Display for ClientError {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match self {
30 Self::TranslationError(msg) => write!(f, "query translation failed: {msg}"),
31 Self::NetworkError(msg) => write!(f, "network error: {msg}"),
32 Self::BackendError { status, message } => {
33 write!(f, "backend error (HTTP {status}): {message}")
34 }
35 Self::ParseError(msg) => write!(f, "failed to parse response: {msg}"),
36 Self::Timeout {
37 elapsed_secs,
38 timeout_secs,
39 } => write!(
40 f,
41 "query timed out after {elapsed_secs}s (limit: {timeout_secs}s)"
42 ),
43 Self::InvalidRequest(msg) => write!(f, "invalid request: {msg}"),
44 }
45 }
46}
47
48impl std::error::Error for ClientError {}