Share error_response and default host allowlist; drop AppResult

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YShymaPrXmc3KYRUg2HMSs
This commit is contained in:
ariandClaude Sonnet 5.5 committed 2026-10-16 08:57:21 -04:00
1 parent 66eb91bf01
commit d022ebeae5
5 files changed
+38 -60

No files matched your search

+7 -12
View File
@@ -1,4 +1,4 @@
//! REST layer (WS-E owns `src/api/`).
//! REST layer.
//!
//! The router contains `/api/v1/*` handlers only (paths are relative; P3
//! nests it). `healthz` is public and mounted outside auth by `main.rs`.
@@ -16,6 +16,7 @@ use std::time::Duration;
use axum::extract::rejection::QueryRejection;
use axum::extract::Query;
use axum::http::StatusCode;
use axum::response::sse::{Event, KeepAlive, Sse};
use axum::{Json, Router};
use futures::Stream;
@@ -23,7 +24,7 @@ use serde::de::DeserializeOwned;
use tokio::sync::mpsc;
use tokio_util::sync::CancellationToken;
use crate::error::AppError;
use crate::error::{error_response, AppError};
use crate::state::AppState;
/// Routes under `/api/v1`, already bound to `state`.
@@ -50,19 +51,13 @@ pub async fn not_found() -> AppError {
AppError::NotFound("no such route".into())
}
/// 405 in the common error shape (`AppError` has no 405 variant, so this
/// renders the same JSON body with the right status).
/// 405 in the common error shape (`AppError` has no 405 variant).
pub async fn method_not_allowed() -> axum::response::Response {
use axum::http::StatusCode;
use axum::response::IntoResponse;
(
error_response(
StatusCode::METHOD_NOT_ALLOWED,
Json(serde_json::json!({"error": {
"code": "method_not_allowed",
"message": "method not allowed",
}})),
"method_not_allowed",
"method not allowed",
)
.into_response()
}
/// Query extraction that reports failures as `AppError::BadRequest`.