Browse Source
Log HTTP headers and response in case of JSONRPC error
refactor-mempool
Roman Zeyde
7 years ago
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
1 changed files with
13 additions and
6 deletions
-
src/daemon.rs
|
|
@ -200,20 +200,27 @@ impl Connection { |
|
|
|
ErrorKind::Connection("disconnected from daemon while receiving".to_owned()) |
|
|
|
})? |
|
|
|
.chain_err(|| "failed to read status")?; |
|
|
|
if status != "HTTP/1.1 200 OK" { |
|
|
|
let msg = format!("request failed {:?}", status); |
|
|
|
bail!(ErrorKind::Connection(msg)); |
|
|
|
} |
|
|
|
let mut headers = vec![]; |
|
|
|
for line in iter { |
|
|
|
let line = line.chain_err(|| ErrorKind::Connection("failed to read".to_owned()))?; |
|
|
|
if line.is_empty() { |
|
|
|
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); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
contents.chain_err(|| ErrorKind::Connection("no reply from daemon".to_owned())) |
|
|
|
if status == "HTTP/1.1 200 OK" { |
|
|
|
contents.chain_err(|| ErrorKind::Connection("no reply from daemon".to_owned())) |
|
|
|
} else { |
|
|
|
let msg = format!( |
|
|
|
"request failed {:?}: {:?} = {:?}", |
|
|
|
status, headers, contents |
|
|
|
); |
|
|
|
bail!(ErrorKind::Connection(msg)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|