server/rest.rs: log full error messages
This commit is contained in:
parent
8daf9fd839
commit
1314000db7
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user