systemprompt_agent/services/shared/
error.rs1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum AgentServiceError {
5 #[error("database operation failed: {0}")]
6 Database(String),
7
8 #[error("repository operation failed: {0}")]
9 Repository(String),
10
11 #[error("network request failed: {0}")]
12 Network(String),
13
14 #[error("authentication failed: {0}")]
15 Authentication(String),
16
17 #[error("authorization failed for resource: {0}")]
18 Authorization(String),
19
20 #[error("validation failed: {0}: {1}")]
21 Validation(String, String),
22
23 #[error("resource not found: {0}")]
24 NotFound(String),
25
26 #[error("service unavailable: {0}")]
27 ServiceUnavailable(String),
28
29 #[error("operation timed out after {0}ms")]
30 Timeout(u64),
31
32 #[error("configuration error: {0}: {1}")]
33 Configuration(String, String),
34
35 #[error("conflict: {0}")]
36 Conflict(String),
37
38 #[error("internal error: {0}")]
39 Internal(String),
40
41 #[error("logging error: {0}")]
42 Logging(String),
43
44 #[error("capacity exceeded: {0}")]
45 Capacity(String),
46}
47
48impl From<sqlx::Error> for AgentServiceError {
49 fn from(err: sqlx::Error) -> Self {
50 Self::Database(err.to_string())
51 }
52}
53
54impl From<crate::repository::RepositoryError> for AgentServiceError {
55 fn from(err: crate::repository::RepositoryError) -> Self {
56 Self::Repository(err.to_string())
57 }
58}
59
60impl From<reqwest::Error> for AgentServiceError {
61 fn from(err: reqwest::Error) -> Self {
62 Self::Network(
63 err.url()
64 .map(|u| u.to_string())
65 .unwrap_or_else(|| "unknown".to_string()),
66 )
67 }
68}
69
70impl From<anyhow::Error> for AgentServiceError {
71 fn from(err: anyhow::Error) -> Self {
72 Self::Configuration("unknown".to_string(), err.to_string())
73 }
74}
75
76pub type Result<T> = std::result::Result<T, AgentServiceError>;