mcp_stdio_proxy/
mcp_error.rs1use axum::{
2 Json,
3 response::{IntoResponse, Response},
4};
5use http::StatusCode;
6use serde::{Deserialize, Serialize};
7use thiserror::Error;
8
9#[derive(Error, Debug)]
10pub enum AppError {
11 #[error("MCP server error: {0}")]
12 McpServerError(#[from] anyhow::Error),
13
14 #[error("serde_json::Error: {0}")]
15 SerdeJsonError(#[from] serde_json::Error),
16}
17
18#[derive(Debug, Serialize, Deserialize)]
19pub struct ErrorOutput {
20 pub error: String,
21}
22
23impl ErrorOutput {
24 pub fn new(error: impl Into<String>) -> Self {
25 Self {
26 error: error.into(),
27 }
28 }
29}
30
31impl IntoResponse for AppError {
32 fn into_response(self) -> Response<axum::body::Body> {
33 let status = match &self {
34 Self::McpServerError(_) => StatusCode::INTERNAL_SERVER_ERROR,
35 Self::SerdeJsonError(_) => StatusCode::BAD_REQUEST,
36 };
37
38 (status, Json(ErrorOutput::new(self.to_string()))).into_response()
39 }
40}