Skip to main content

systemprompt_models/api/errors/
config_plane.rs

1//! The `ConfigPlaneError` → [`ApiError`] mapping.
2//!
3//! A write refused because the plane is file-managed answers 409 with the
4//! `config_plane_file_managed` key, an unknown plane 404, an invalid
5//! declaration 400, and every backend failure 500 with the cause logged.
6//!
7//! Copyright (c) systemprompt.io — Business Source License 1.1.
8//! See <https://systemprompt.io> for licensing details.
9
10use systemprompt_provider_contracts::ConfigPlaneError;
11
12use super::ApiError;
13
14const PLANE_FAILURE: &str = "Config plane operation failed";
15
16impl From<ConfigPlaneError> for ApiError {
17    fn from(err: ConfigPlaneError) -> Self {
18        match err {
19            ConfigPlaneError::FileManaged { .. } => {
20                Self::conflict(err.to_string()).with_error_key("config_plane_file_managed")
21            },
22            ConfigPlaneError::UnknownPlane(_) => Self::not_found(err.to_string()),
23            ConfigPlaneError::Invalid { .. } => Self::bad_request(err.to_string()),
24            other => Self::internal(PLANE_FAILURE, other),
25        }
26    }
27}