Files
tkmind_go/crates/goose-server/src/routes/errors.rs
T
Douwe Osinga e7ca2e3bf7 Agent extension api (#5281)
Co-authored-by: Douwe Osinga <douwe@squareup.com>
2025-10-29 11:16:06 -04:00

40 lines
846 B
Rust

use axum::{
http::StatusCode,
response::{IntoResponse, Response},
Json,
};
use serde::Serialize;
use utoipa::ToSchema;
#[derive(Debug, Serialize, ToSchema)]
pub struct ErrorResponse {
pub message: String,
#[serde(skip)]
pub status: StatusCode,
}
impl ErrorResponse {
pub(crate) fn internal(message: impl Into<String>) -> Self {
Self {
message: message.into(),
status: StatusCode::INTERNAL_SERVER_ERROR,
}
}
}
impl IntoResponse for ErrorResponse {
fn into_response(self) -> Response {
let body = Json(serde_json::json!({
"message": self.message,
}));
(self.status, body).into_response()
}
}
impl From<anyhow::Error> for ErrorResponse {
fn from(err: anyhow::Error) -> Self {
Self::internal(err.to_string())
}
}