From 44c00c0dfd70196fef412cafbd0eff7dfa0f7602 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 15 Feb 2019 09:55:12 +0100 Subject: [PATCH] server/rest.rs: log full error messages --- src/server/formatter.rs | 11 ++++++++++- src/server/rest.rs | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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::() { + message = &data.0; + } log::error!("{}: {} {}: [client {}] {}", path, status.as_str(), reason, client, message); }