mirror of
https://github.com/moghtech/komodo.git
synced 2026-10-29 16:06:57 +00:00
properly forward periphery trace into core error trace
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
use anyhow::anyhow;
|
||||
use async_timing_util::unix_timestamp_ms;
|
||||
use axum::{http::StatusCode, TypedHeader, headers::ContentType};
|
||||
use monitor_types::entities::update::Log;
|
||||
use run_command::{async_run_command, CommandOutput};
|
||||
use serror::serialize_error_pretty;
|
||||
|
||||
use crate::state::State;
|
||||
|
||||
@@ -59,3 +61,11 @@ pub fn output_into_log(stage: &str, command: String, start_ts: i64, output: Comm
|
||||
end_ts: unix_timestamp_ms() as i64,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_response_error(e: anyhow::Error) -> (StatusCode, TypedHeader<ContentType>, String) {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
TypedHeader(ContentType::json()),
|
||||
serialize_error_pretty(e),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ use axum::{
|
||||
};
|
||||
|
||||
use resolver_api::Resolver;
|
||||
use serror::serialize_error;
|
||||
use termination_signal::tokio::immediate_term_handle;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -23,6 +22,10 @@ mod state;
|
||||
use requests::PeripheryRequest;
|
||||
use state::State;
|
||||
|
||||
use crate::helpers::into_response_error;
|
||||
|
||||
type ResponseResult<T> = Result<T, (StatusCode, TypedHeader<ContentType>, String)>;
|
||||
|
||||
async fn app() -> anyhow::Result<()> {
|
||||
let state = State::load().await?;
|
||||
|
||||
@@ -44,17 +47,15 @@ async fn app() -> anyhow::Result<()> {
|
||||
if let Err(e) = &res {
|
||||
debug!("request {req_id} SPAWN ERROR: {e:#?}");
|
||||
}
|
||||
let res =
|
||||
res.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, serialize_error(e)))?;
|
||||
let res = res.map_err(into_response_error)?;
|
||||
if let Err(e) = &res {
|
||||
debug!("request {req_id} ERROR: {e:#?}");
|
||||
}
|
||||
let res =
|
||||
res.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, serialize_error(e)))?;
|
||||
let res = res.map_err(into_response_error)?;
|
||||
let elapsed = timer.elapsed();
|
||||
info!("request {req_id} | resolve time: {elapsed:?}");
|
||||
debug!("request {req_id} RESPONSE: {res}");
|
||||
Result::<_, (StatusCode, String)>::Ok((TypedHeader(ContentType::json()), res))
|
||||
ResponseResult::Ok((TypedHeader(ContentType::json()), res))
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user