systemprompt_api/routes/agent/contexts/webhook/
error.rs1use systemprompt_agent::AgentError;
7use systemprompt_traits::RepositoryError;
8
9use crate::error::ApiHttpError;
10
11#[derive(Debug, thiserror::Error)]
12pub enum LoadEventError {
13 #[error("Unknown event type: {0}")]
14 UnknownEventType(String),
15 #[error(transparent)]
16 Agent(#[from] AgentError),
17 #[error(transparent)]
18 Repository(#[from] RepositoryError),
19 #[error("{entity} not found: {id}")]
20 NotFound { entity: &'static str, id: String },
21 #[error("Invalid {field}: {source}")]
22 Deserialize {
23 field: &'static str,
24 #[source]
25 source: serde_json::Error,
26 },
27 #[error("{0} is required for this event type")]
28 MissingField(&'static str),
29 #[error("Invalid payload: {0}")]
30 InvalidPayload(String),
31}
32
33impl From<LoadEventError> for ApiHttpError {
34 fn from(err: LoadEventError) -> Self {
35 match err {
36 LoadEventError::Agent(e) => Self::from(e),
37 LoadEventError::Repository(e) => Self::from(e),
38 e @ LoadEventError::NotFound { .. } => Self::not_found(e.to_string()),
39 e @ (LoadEventError::UnknownEventType(_)
40 | LoadEventError::Deserialize { .. }
41 | LoadEventError::MissingField(_)
42 | LoadEventError::InvalidPayload(_)) => Self::bad_request(e.to_string()),
43 }
44 }
45}