fix local markdown attachment regressions
This commit is contained in:
@@ -4,12 +4,16 @@ use crate::editor_actor::EditorRuntimeActor;
|
||||
use crate::local_folder_watcher_registry::LocalFolderWatcherRegistry;
|
||||
use crate::middleware::request_context::inject_request_context;
|
||||
use crate::routes::build_router;
|
||||
use axum::extract::Request;
|
||||
use axum::middleware::Next;
|
||||
use axum::response::Response;
|
||||
use axum::Router;
|
||||
use control_plane::{ControlPlaneStore, SqliteControlPlaneStore};
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::sync::Arc;
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::{error, warn};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AppConfig {
|
||||
@@ -192,10 +196,43 @@ fn open_control_plane_store() -> SqliteControlPlaneStore {
|
||||
|
||||
pub fn build_app(state: AppState) -> Router {
|
||||
build_router(state)
|
||||
.layer(TraceLayer::new_for_http())
|
||||
.layer(TraceLayer::new_for_http().on_failure(()))
|
||||
.layer(axum::middleware::from_fn(log_failed_response))
|
||||
.layer(axum::middleware::from_fn(inject_request_context))
|
||||
}
|
||||
|
||||
async fn log_failed_response(request: Request, next: Next) -> Response {
|
||||
let method = request.method().clone();
|
||||
let uri = request.uri().clone();
|
||||
let response = next.run(request).await;
|
||||
let status = response.status();
|
||||
if status.is_server_error() {
|
||||
let error_code = response
|
||||
.headers()
|
||||
.get("x-error-code")
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.unwrap_or("");
|
||||
if error_code == "convex_retired" {
|
||||
warn!(
|
||||
method = %method,
|
||||
uri = %uri,
|
||||
status = %status,
|
||||
error_code = %error_code,
|
||||
"退役 Convex 兼容路径被请求"
|
||||
);
|
||||
} else {
|
||||
error!(
|
||||
method = %method,
|
||||
uri = %uri,
|
||||
status = %status,
|
||||
error_code = %error_code,
|
||||
"mnote-web 请求返回服务端错误"
|
||||
);
|
||||
}
|
||||
}
|
||||
response
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user