claude_codex/anthropic/
error.rs1use axum::{
2 Json,
3 http::StatusCode,
4 response::{IntoResponse, Response},
5};
6use serde::Serialize;
7
8#[derive(Debug, Clone, Serialize)]
9pub struct ErrorEnvelope {
10 #[serde(rename = "type")]
11 pub kind: &'static str,
12 pub error: ErrorDetail,
13}
14
15#[derive(Debug, Clone, Serialize)]
16pub struct ErrorDetail {
17 #[serde(rename = "type")]
18 pub kind: String,
19 pub message: String,
20}
21
22pub fn json_error(
23 status: StatusCode,
24 kind: impl Into<String>,
25 message: impl Into<String>,
26) -> Response {
27 (
28 status,
29 Json(ErrorEnvelope {
30 kind: "error",
31 error: ErrorDetail {
32 kind: kind.into(),
33 message: message.into(),
34 },
35 }),
36 )
37 .into_response()
38}