1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
use Error;
use Error as StdError;
// // Helper conversions (can add more as needed)
// // Conversion from reqwest::Error
// // Todo: Add feature flag for reqwest to avoid unnecessary dependency
// //#[cfg(feature = "reqwest")]
// impl From<reqwest::Error> for EmbeddingError {
// fn from(err: reqwest::Error) -> Self {
// let boxed_err = Box::new(err) as Box<dyn StdError + Send + Sync>;
// // Try to classify based on reqwest error kind
// let err_ref = boxed_err.downcast_ref::<reqwest::Error>().unwrap(); // Safe cast back
// if err_ref.is_connect() || err_ref.is_timeout() {
// EmbeddingError::Network(boxed_err)
// } else if err_ref.is_status() {
// let status = err_ref.status();
// EmbeddingError::ApiError {
// status_code: status.map(|s| s.as_u16()),
// message: format!("HTTP status error: {}", status.unwrap_or_default()),
// source: Some(boxed_err), // Include the original reqwest::Error as source
// }
// } else if err_ref.is_request() || err_ref.is_body() || err_ref.is_decode() {
// // These could be API errors (bad request format) or network issues,
// // or internal serialization issues. ApiError or ImplementationSpecific might fit.
// EmbeddingError::ApiError {
// status_code: None, // Status not necessarily available
// message: format!("API request/response handling error: {}", boxed_err),
// source: Some(boxed_err),
// }
// } else {
// // Default to ImplementationSpecific or wrap directly
// EmbeddingError::ImplementationSpecific(boxed_err)
// // Or potentially: EmbeddingError::External(boxed_err)
// }
// }
// }
// // Conversion from serde_json::Error (often happens when parsing API responses)
// impl From<serde_json::Error> for EmbeddingError {
// fn from(err: serde_json::Error) -> Self {
// EmbeddingError::ApiError { // Often implies unexpected API response format
// status_code: None,
// message: format!("Failed to parse JSON response: {}", err),
// source: Some(Box::new(err)),
// }
// }
// }
// // Conversion from std::io::Error (might occur with local models)
// impl From<std::io::Error> for EmbeddingError {
// fn from(err: std::io::Error) -> Self {
// // Could be ModelError (file not found) or ImplementationSpecific
// EmbeddingError::ModelError(Box::new(err))
// }
// }