generalbots/botserver/src/designer/canvas_api/error.rs
Rodrigo Rodriguez (Pragmatismo) 037db5c381 feat: Major workspace reorganization and documentation update
- Add comprehensive documentation in botbook/ with 12 chapters
- Add botapp/ Tauri desktop application
- Add botdevice/ IoT device support
- Add botlib/ shared library crate
- Add botmodels/ Python ML models service
- Add botplugin/ browser extension
- Add botserver/ reorganized server code
- Add bottemplates/ bot templates
- Add bottest/ integration tests
- Add botui/ web UI server
- Add CI/CD workflows in .forgejo/workflows/
- Add AGENTS.md and PROD.md documentation
- Add dependency management scripts (DEPENDENCIES.sh/ps1)
- Remove legacy src/ structure and migrations
- Clean up temporary and backup files
2026-04-19 08:14:25 -03:00

44 lines
1.5 KiB
Rust

use axum::{http::StatusCode, response::IntoResponse};
#[derive(Debug, Clone)]
pub enum CanvasError {
DatabaseConnection,
NotFound,
ElementNotFound,
ElementLocked,
CreateFailed,
UpdateFailed,
DeleteFailed,
ExportFailed(String),
InvalidInput(String),
}
impl std::fmt::Display for CanvasError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::DatabaseConnection => write!(f, "Database connection failed"),
Self::NotFound => write!(f, "Canvas not found"),
Self::ElementNotFound => write!(f, "Element not found"),
Self::ElementLocked => write!(f, "Element is locked"),
Self::CreateFailed => write!(f, "Failed to create"),
Self::UpdateFailed => write!(f, "Failed to update"),
Self::DeleteFailed => write!(f, "Failed to delete"),
Self::ExportFailed(msg) => write!(f, "Export failed: {msg}"),
Self::InvalidInput(msg) => write!(f, "Invalid input: {msg}"),
}
}
}
impl std::error::Error for CanvasError {}
impl IntoResponse for CanvasError {
fn into_response(self) -> axum::response::Response {
let status = match self {
Self::NotFound | Self::ElementNotFound => StatusCode::NOT_FOUND,
Self::ElementLocked => StatusCode::FORBIDDEN,
Self::InvalidInput(_) => StatusCode::BAD_REQUEST,
_ => StatusCode::INTERNAL_SERVER_ERROR,
};
(status, self.to_string()).into_response()
}
}