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 or an operation the plane does not support (export, a scoped
6//! apply) 400, and every backend failure 500 with the cause logged.
7//!
8//! Copyright (c) systemprompt.io — Business Source License 1.1.
9//! See <https://systemprompt.io> for licensing details.
10
11use systemprompt_provider_contracts::ConfigPlaneError;
12
13use super::ApiError;
14
15const PLANE_FAILURE: &str = "Config plane operation failed";
16
17impl From<ConfigPlaneError> for ApiError {
18    fn from(err: ConfigPlaneError) -> Self {
19        match err {
20            ConfigPlaneError::FileManaged { .. } => {
21                Self::conflict(err.to_string()).with_error_key("config_plane_file_managed")
22            },
23            ConfigPlaneError::UnknownPlane(_) => Self::not_found(err.to_string()),
24            ConfigPlaneError::Invalid { .. } | ConfigPlaneError::Unsupported { .. } => {
25                Self::bad_request(err.to_string())
26            },
27            other => Self::internal(PLANE_FAILURE, other),
28        }
29    }
30}