Browse Source

Log HTTP headers and response in case of JSONRPC error

refactor-mempool
Roman Zeyde 7 years ago
parent
commit
ecc8a2004e
No known key found for this signature in database GPG Key ID: 87CAE5FA46917CBB
  1. 17
      src/daemon.rs

17
src/daemon.rs

@ -200,20 +200,27 @@ impl Connection {
ErrorKind::Connection("disconnected from daemon while receiving".to_owned()) ErrorKind::Connection("disconnected from daemon while receiving".to_owned())
})? })?
.chain_err(|| "failed to read status")?; .chain_err(|| "failed to read status")?;
if status != "HTTP/1.1 200 OK" { let mut headers = vec![];
let msg = format!("request failed {:?}", status);
bail!(ErrorKind::Connection(msg));
}
for line in iter { for line in iter {
let line = line.chain_err(|| ErrorKind::Connection("failed to read".to_owned()))?; let line = line.chain_err(|| ErrorKind::Connection("failed to read".to_owned()))?;
if line.is_empty() { if line.is_empty() {
in_header = false; // next line should contain the actual response. in_header = false; // next line should contain the actual response.
} else if !in_header { } else if in_header {
headers.push(line);
} else {
contents = Some(line); contents = Some(line);
break; break;
} }
} }
if status == "HTTP/1.1 200 OK" {
contents.chain_err(|| ErrorKind::Connection("no reply from daemon".to_owned())) contents.chain_err(|| ErrorKind::Connection("no reply from daemon".to_owned()))
} else {
let msg = format!(
"request failed {:?}: {:?} = {:?}",
status, headers, contents
);
bail!(ErrorKind::Connection(msg));
}
} }
} }

Loading…
Cancel
Save