server/rest.rs: log full error messages

This commit is contained in:
Dietmar Maurer 2019-02-15 09:55:12 +01:00
parent 7171b3e079
commit 44c00c0dfd
2 changed files with 15 additions and 2 deletions

View File

@ -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<Body>,
@ -55,6 +58,8 @@ fn json_format_error(err: Error) -> Response<Body> {
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<Body> {
"success": false
});
json_response(result)
let mut response = json_response(result);
response.extensions_mut().insert(ErrorMessageExtension(message));
response
}
pub static EXTJS_FORMATTER: OutputFormatter = OutputFormatter {

View File

@ -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::<ErrorMessageExtension>() {
message = &data.0;
}
log::error!("{}: {} {}: [client {}] {}", path, status.as_str(), reason, client, message);
}