edenapi: check HTTP status code

Summary: Previously, `edenapi` would unconditionally attempt to parse the response body as CBOR, resulting in cryptic error messages if the server had returned an error instead of the expected content. Instead, we should first check that the request was successful, and only then attempt to parse the body.

Reviewed By: quark-zju

Differential Revision: D15426868

fbshipit-source-id: ceaf0d6691b509bcd934d6b99ceefb3e83e798ca
This commit is contained in:
Arun Kulshreshtha 2019-05-20 22:55:53 -07:00 committed by Facebook Github Bot
parent bb67907b7b
commit 14bf3a15b0

View File

@ -247,8 +247,19 @@ impl EdenApiCurlClient {
let start = Instant::now();
driver.perform(|res| {
let easy = res?;
let mut easy = res?;
let code = easy.response_code()?;
let data = easy.get_ref().data();
if code >= 400 {
let msg = String::from_utf8_lossy(data);
bail!(
"Received HTTP status code {} with response: {:?}",
code,
msg
);
}
let response = serde_cbor::from_slice::<T>(data)?;
response_cb(response)
})?;