1use std::fmt;
2
3#[derive(Debug)]
5pub enum BasetenError {
6 MissingApiKey,
8
9 MissingModelUrl,
11
12 InvalidEndpoint(String),
14
15 ProviderError(String),
17}
18
19impl fmt::Display for BasetenError {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 match self {
22 BasetenError::MissingApiKey => {
23 write!(
24 f,
25 "Baseten API key not found. Set BASETEN_API_KEY environment variable or provide api_key explicitly."
26 )
27 }
28 BasetenError::MissingModelUrl => {
29 write!(
30 f,
31 "Model URL is required for embeddings. Please set modelURL option for embeddings."
32 )
33 }
34 BasetenError::InvalidEndpoint(msg) => {
35 write!(f, "Invalid endpoint: {}", msg)
36 }
37 BasetenError::ProviderError(msg) => {
38 write!(f, "Provider error: {}", msg)
39 }
40 }
41 }
42}
43
44impl std::error::Error for BasetenError {}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_error_display() {
52 let error = BasetenError::MissingApiKey;
53 assert!(error.to_string().contains("BASETEN_API_KEY"));
54
55 let error = BasetenError::MissingModelUrl;
56 assert!(error.to_string().contains("Model URL is required"));
57
58 let error = BasetenError::InvalidEndpoint("/predict not supported".to_string());
59 assert!(error.to_string().contains("/predict not supported"));
60
61 let error = BasetenError::ProviderError("test error".to_string());
62 assert!(error.to_string().contains("test error"));
63 }
64}