diff --git a/src/server/formatter.rs b/src/server/formatter.rs index eb3c33d1..c46fc822 100644 --- a/src/server/formatter.rs +++ b/src/server/formatter.rs @@ -6,6 +6,9 @@ use crate::api::router::RpcEnvironment; use hyper::{Body, Response, StatusCode}; use hyper::header; +/// Extension to set error message for server side logging +pub struct ErrorMessageExtension(pub String); + pub struct OutputFormatter { pub format_result: fn(data: Value, rpcenv: &RpcEnvironment) -> Response
, @@ -55,6 +58,8 @@ fn json_format_error(err: Error) -> Response { header::HeaderValue::from_static(JSON_CONTENT_TYPE)); *response.status_mut() = StatusCode::BAD_REQUEST; + response.extensions_mut().insert(ErrorMessageExtension(err.to_string())); + response } @@ -95,7 +100,11 @@ fn extjs_format_error(err: Error) -> Response { "success": false }); - json_response(result) + let mut response = json_response(result); + + response.extensions_mut().insert(ErrorMessageExtension(message)); + + response } pub static EXTJS_FORMATTER: OutputFormatter = OutputFormatter { diff --git a/src/server/rest.rs b/src/server/rest.rs index 8af00b2a..954435a1 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -67,7 +67,11 @@ impl ApiService { if !status.is_success() { let reason = status.canonical_reason().unwrap_or("unknown reason"); let client = "unknown"; // fixme: howto get peer_addr ? - let message = "request failed"; + + let mut message = "request failed"; + if let Some(data) = resp.extensions().get::