atomr_agents_coding_cli_harness_web/
error.rs1use axum::http::StatusCode;
4use axum::response::{IntoResponse, Response};
5use axum::Json;
6use serde_json::json;
7
8use atomr_agents_coding_cli_harness::HarnessError;
9
10#[derive(Debug, thiserror::Error)]
11pub enum WebError {
12 #[error("bad request: {0}")]
13 BadRequest(String),
14
15 #[error("not found: {0}")]
16 NotFound(String),
17
18 #[error(transparent)]
19 Harness(#[from] HarnessError),
20
21 #[error(transparent)]
22 Serde(#[from] serde_json::Error),
23}
24
25impl IntoResponse for WebError {
26 fn into_response(self) -> Response {
27 let (status, msg) = match &self {
28 WebError::BadRequest(m) => (StatusCode::BAD_REQUEST, m.clone()),
29 WebError::NotFound(m) => (StatusCode::NOT_FOUND, m.clone()),
30 WebError::Harness(h) => match h {
31 HarnessError::UnknownVendor(_) => (StatusCode::BAD_REQUEST, h.to_string()),
32 HarnessError::InvalidRequest(_) => (StatusCode::BAD_REQUEST, h.to_string()),
33 HarnessError::InvalidWorkdir(_) => (StatusCode::BAD_REQUEST, h.to_string()),
34 HarnessError::SessionNotFound(_) => (StatusCode::NOT_FOUND, h.to_string()),
35 _ => (StatusCode::INTERNAL_SERVER_ERROR, h.to_string()),
36 },
37 WebError::Serde(_) => (StatusCode::BAD_REQUEST, self.to_string()),
38 };
39 (status, Json(json!({ "error": msg }))).into_response()
40 }
41}